本文整理汇总了PHP中UploadedFile::addFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::addFilter方法的具体用法?PHP UploadedFile::addFilter怎么用?PHP UploadedFile::addFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::addFilter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
function validate($newItem)
{
$extraFields = $this->extraField->getCategoryFieldsWithOptions($newItem->categoryId);
foreach ($extraFields as $field) {
$fieldId = $field['fieldId'];
if ($field['required'] && (empty($newItem->extraField) || empty($newItem->extraField[$fieldId]))) {
return "You don't fill required field " . $field['name'];
}
if ($field['type'] == 'file') {
$file = new UploadedFile('extraField_' . $fieldId . '_file');
$extensions = preg_split('/\\s*,\\s*/', $field['config']['extensions']);
$file->addFilter('extension', $extensions);
$file->addFilter('maxSize', intval($field['config']['maxSize']) * 1024);
if ($file->wasUploaded()) {
try {
$file->validate();
} catch (Exception $e) {
return $e->getMessage();
}
}
}
}
}
示例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: 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;
}
示例4: 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"));
}
示例5: 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);
}