本文整理匯總了PHP中ModuleAdminController::postImage方法的典型用法代碼示例。如果您正苦於以下問題:PHP ModuleAdminController::postImage方法的具體用法?PHP ModuleAdminController::postImage怎麽用?PHP ModuleAdminController::postImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ModuleAdminController
的用法示例。
在下文中一共展示了ModuleAdminController::postImage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: postImage
/**
* @param Employee $object
*
* @return bool
*/
protected function postImage($id)
{
$ret = parent::postImage($id);
if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) {
if ($error = ImageManager::validateUpload($_FILES['image'], 4000000)) {
return $this->displayError($this->l('Invalid image'));
} else {
$path = _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '.' . $this->imageType;
$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
if (!$tmp_name) {
return false;
}
if (!move_uploaded_file($_FILES['image']['tmp_name'], $tmp_name)) {
return false;
}
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($tmp_name)) {
$this->errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
}
// Copy new image
if (empty($this->errors) && !ImageManager::resize($tmp_name, $path, (int) $width, (int) $height, $ext ? $ext : $this->imageType)) {
$this->errors[] = Tools::displayError('An error occurred while uploading the image.');
}
if (count($this->errors)) {
return false;
}
if ($this->afterImageUpload()) {
unlink($tmp_name);
// return true;
}
$posts_types = BlogImageType::GetImageAllType('post');
foreach ($posts_types as $image_type) {
$dir = _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg';
if (file_exists($dir)) {
unlink($dir);
}
}
foreach ($posts_types as $image_type) {
ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
}
}
}
return $ret;
}