本文整理汇总了PHP中UploadedFile::setSavePath方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::setSavePath方法的具体用法?PHP UploadedFile::setSavePath怎么用?PHP UploadedFile::setSavePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::setSavePath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadSiteImageAction
function uploadSiteImageAction($siteId)
{
$this->viewClass = 'JsonView';
$siteId = intval($siteId);
$site = $this->site->findByPk($siteId);
$siteImage = new UploadedFile("siteImage");
$siteImage->addFilter("extension", array("jpg", "png", "gif"));
$thumbsPath = Config::get("SITES_THUMBS_PATH");
$siteImage->setSavePath($thumbsPath);
$siteImage->save();
$newImageSrc = $siteImage->getSavedFileName();
if ($newImageSrc) {
if ($site->imageSrc) {
$oldFilePath = $thumbsPath . basename($site->imageSrc);
if (file_exists($oldFilePath)) {
unlink($oldFilePath);
}
}
$site->imageSrc = $newImageSrc;
$site->save();
}
$site->updateImageSrc(false);
$this->set('status', 'ok');
$this->set('imageSrc', $site->imageSrc);
}
示例2: savePackageAction
function savePackageAction($packageId = null)
{
$fields = array('name', 'amount', 'allopassId', 'allopassNumber', 'priority', 'description', 'siteDescriptionMaxLength', 'maxKeywordsCountPerSite', 'backLinkMandatory', 'siteDescriptionHtmlEnabled', 'siteDescriptionHtmlAllowedTags', 'siteDescriptionHtmlAllowedCssProperties', 'siteDescriptionMinLength');
$data = $this->request->getArray($fields);
$package = empty($packageId) ? new PackageRecord() : $this->package->findByPk($packageId);
$package->fromArray($data);
$siteImage = new UploadedFile("uploadImage");
$siteImage->addFilter("extension", array("jpg", "png", "gif"));
if ($siteImage->wasUploaded()) {
$thumbsPath = Config::get("PACKAGES_THUMBS_PATH");
$siteImage->setSavePath($thumbsPath);
$siteImage->save();
$newImageSrc = $siteImage->getSavedFileName();
if ($newImageSrc) {
if (!empty($package->imageSrc)) {
$oldFilePath = $thumbsPath . basename($package->imageSrc);
if (file_exists($oldFilePath)) {
unlink($oldFilePath);
}
}
$package->imageSrc = $newImageSrc;
}
}
$package->save();
$this->redirect($this->moduleLink("package"));
}
示例3: saveExtraFieldsValues
function saveExtraFieldsValues($item, $newItem)
{
$fields = $this->getCategoryFieldsWithOptions($item->categoryId);
$itemId = $item->siteId;
$c = new Criteria();
$c->addInnerJoin('extrafields', 'extrafields.fieldId', 'extrafieldvalues.fieldId');
$c->add('type', 'file');
$files = $this->extraFieldValue->getArray($c, 'text', 'extrafields.fieldId');
$c = new Criteria();
$c->add("itemId", $itemId);
$this->extraFieldValue->del($c);
foreach ($fields as $fieldId => $field) {
$extraFieldValue = new ExtraFieldValueRecord();
$extraFieldValue->itemId = $itemId;
$extraFieldValue->fieldId = $fieldId;
if (!isset($newItem->extraField[$fieldId])) {
continue;
}
$newItemExtraFieldData = $newItem->extraField[$fieldId];
try {
switch ($field['type']) {
case "text":
case "textarea":
$extraFieldValue->text = $newItemExtraFieldData;
break;
case "select":
case "radio":
if (!isset($field['options'][$newItemExtraFieldData])) {
continue 2;
}
case "range":
$extraFieldValue->value = $newItemExtraFieldData;
break;
case 'url':
$extraFieldValue->text = serialize($newItemExtraFieldData);
break;
case "checkbox":
$value = 0;
foreach ($newItemExtraFieldData as $checkBoxValue) {
if (!isset($field['options'][$checkBoxValue])) {
continue 3;
}
$value += pow(2, $checkBoxValue - 1);
//minus 1 because we count from 1,2,3,4.. to have 1,2,4,8
}
$extraFieldValue->value = $value;
break;
case 'file':
$file = new UploadedFile('extraField_' . $fieldId . '_file');
if (!empty($files[$fieldId])) {
$data = unserialize($files[$fieldId]);
} else {
$data = array();
}
$data['title'] = $newItemExtraFieldData['title'];
if ($file->wasUploaded()) {
$filesPath = CODE_ROOT_DIR . 'uploads/files/';
$file->setSavePath($filesPath);
$file->save();
$fileSrc = $file->getSavedFileName();
$data['fileSrc'] = $fileSrc;
}
$extraFieldValue->text = serialize($data);
}
$extraFieldValue->save();
} catch (Exception $e) {
}
}
$this->site->updateByPk(array("haveExtraFields" => !empty($newItem->extraField) ? "1" : "0"), $itemId);
}
示例4: saveCategoryAction
function saveCategoryAction()
{
$rebuild = false;
$edit = !empty($this->request->categoryId);
$imageSrc = false;
try {
$file = new UploadedFile("categoryImage");
$file->addFilter("extension", array("jpg", "gif", "png"));
//check and save image
if ($file->wasUploaded()) {
$file->setSavePath(CODE_ROOT_DIR . 'uploads/images_categories/');
$file->save();
$imageSrc = $file->getSavedFileName();
}
} catch (Exception $e) {
}
if (!$edit && $imageSrc == false) {
$imageSrc = 'defaultCategoryImage.gif';
}
//create and save new category
$fields = $this->request->getArray(array("name", "urlName", "navigationName", "title", "headerDescription", "possibleTender", "description", "metaDescription", "parentCategoryId", "forbidden"));
if ($edit) {
$category = $this->category->findByPk($this->request->categoryId);
//handle categoryParentId change
if ($category->parentCategoryId != $this->request->parentCategoryId && $category->changeParent($this->request->parentCategoryId)) {
$rebuild = true;
}
} else {
$category = new CategoryRecord();
}
$category->fromArray($fields);
if ($imageSrc) {
if ($edit) {
$category->removeImage();
}
$category->imageSrc = $imageSrc;
}
if (empty($category->urlName)) {
$category->urlName = $category->name;
}
$excludeCategoryId = $edit ? $category->categoryId : false;
$category->urlName = $this->category->getFreeUrlName($category->urlName, $excludeCategoryId);
$category->save();
if (!$edit) {
$this->categoryParent->addNode($this->request->parentCategoryId, $category->categoryId);
}
if ($rebuild) {
$this->categoryParent->moveNode($category->categoryId, $category->parentCategoryId);
$this->category->updateValidatedSitesCount();
}
$redirect = AppRouter::getRewrittedUrl("/admin/category/index/" . $category->parentCategoryId);
$this->redirect($redirect);
}