本文整理汇总了PHP中UploadedFile::save方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::save方法的具体用法?PHP UploadedFile::save怎么用?PHP UploadedFile::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadSiteImageAction
function uploadSiteImageAction($siteId)
{
$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");
$newImageSrc = $siteImage->save($thumbsPath);
if ($newImageSrc) {
if ($site->imageSrc) {
$oldFilePath = $thumbsPath . basename($site->imageSrc);
if (file_exists($oldFilePath)) {
unlink($oldFilePath);
}
}
$site->imageSrc = $newImageSrc;
$site->save();
}
$site->updateImageSrc(false);
echo "<html><body>" . $site->imageSrc . "</body></html>";
$this->autoRender = false;
}
示例2: 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);
}
示例3: uploadEchFile
private function uploadEchFile($file)
{
if (Yii::app()->user->isAdmin()) {
$biobank_id = $_SESSION['biobank_id'];
} else {
$biobank_id = Yii::app()->user->biobank_id;
}
$model = new UploadedFile();
$_SESSION['biobank_id'] = $biobank_id;
if (isset($file)) {
$tempFilename = $file["tmp_name"];
$filename = $file["name"];
if ($file['size'] < 15000000) {
$splitted = explode(".", $filename);
$extension = end($splitted);
if (in_array($extension, array('xls', 'xlsx'))) {
$model->filename = $tempFilename;
$model->metadata['biobank_id'] = $biobank_id;
$model->uploadDate = new MongoDate();
if ($model->save()) {
$model->filename = $filename;
if ($model->save()) {
Yii::app()->user->setFlash('success', "{$filename} successfully saved with id {$model->_id}.");
return $model->_id;
} else {
Yii::app()->user->setFlash('error', "Saving error");
return null;
}
} else {
Yii::app()->user->setFlash('error', "Saving error");
return null;
}
} else {
Yii::app()->user->setFlash('error', "{$filename} is not a valid file.");
return null;
}
} else {
Yii::app()->user->setFlash('error', "{$filename} is too big");
return null;
}
} else {
return null;
}
}
示例4: executeUpload
public function executeUpload(sfWebRequest $request)
{
$this->forward404Unless($request->isXmlHttpRequest());
/** @var Role $role */
$role = $this->getRoute()->getObject();
$response = array();
// Load files
if ($request->getMethod() == 'GET') {
foreach ($role->Files as $uploadedFile) {
$response[] = $uploadedFile->getResponseObject();
}
} else {
$dir_path = '/role';
$fileValidator = new sfValidatorFile(array('required' => true, 'path' => sfConfig::get('sf_upload_dir') . $dir_path));
foreach ($request->getFiles('files') as $file) {
$validatedFile = $fileValidator->clean($file);
$uploadedFile = new UploadedFile();
$uploadedFile->path = $dir_path . '/' . $validatedFile->save();
$uploadedFile->mime_type = $validatedFile->getType();
$uploadedFile->name = $validatedFile->getOriginalName();
$uploadedFile->save();
$role->Files->add($uploadedFile);
$response[] = $uploadedFile->getResponseObject();
}
$role->save();
}
$this->setLayout(false);
$this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
return $this->renderText(json_encode($response));
}
示例5: 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);
}
示例6: 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"));
}
示例7: 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);
}