當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ImageManager::validateUpload方法代碼示例

本文整理匯總了PHP中ImageManager::validateUpload方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageManager::validateUpload方法的具體用法?PHP ImageManager::validateUpload怎麽用?PHP ImageManager::validateUpload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ImageManager的用法示例。


在下文中一共展示了ImageManager::validateUpload方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: postProcess

 protected function postProcess()
 {
     $errors = '';
     if (Tools::isSubmit('deleteImage')) {
         if (!file_exists(dirname(__FILE__) . '/img/' . $this->_getUserImg())) {
             $errors .= $this->displayError($this->l('This action cannot be taken.'));
         } else {
             unlink(dirname(__FILE__) . '/img/' . $this->_getUserImg());
             Tools::redirectAdmin('index.php?tab=AdminModules&conf=4&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id));
         }
     }
     if (Tools::isSubmit('submitUpdateScrolltop')) {
         if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {
             if ($error = ImageManager::validateUpload($_FILES['image'])) {
                 $errors .= $this->displayError($error);
             } elseif (!ImageManager::resize($_FILES['image']['tmp_name'], dirname(__FILE__) . '/img/' . $this->_getUserImg())) {
                 $errors .= $this->displayError($this->l('An error occurred during the image upload.'));
             }
         }
         foreach ($this->_scrollParams as $param => $value) {
             if ($val = (int) Tools::getValue($param)) {
                 $this->_setScrollParam($param, $val);
             } else {
                 $errors .= $this->displayError($this->l('"' . $param . '" is not valid.'));
             }
         }
         if (!$errors) {
             Tools::redirectAdmin('index.php?tab=AdminModules&conf=4&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id));
         }
     }
     $this->_html .= $errors;
 }
開發者ID:ecssjapan,項目名稱:guiding-you-afteropen,代碼行數:32,代碼來源:scrolltop.php

示例2: postProcess

 public function postProcess()
 {
     if (Tools::isSubmit('submitStoreConf')) {
         if (!($languages = Language::getLanguages(true))) {
             return false;
         }
         $text = array();
         foreach ($languages as $lang) {
             $text[$lang['id_lang']] = Tools::getValue('BLOCKSTORE_TEXT_' . $lang['id_lang']);
         }
         Configuration::updateValue('BLOCKSTORE_TEXT', $text);
         if (isset($_FILES['BLOCKSTORE_IMG']) && isset($_FILES['BLOCKSTORE_IMG']['tmp_name']) && !empty($_FILES['BLOCKSTORE_IMG']['tmp_name'])) {
             if ($error = ImageManager::validateUpload($_FILES['BLOCKSTORE_IMG'], 4000000)) {
                 return $this->displayError($this->l('Invalid image.'));
             } else {
                 $ext = substr($_FILES['BLOCKSTORE_IMG']['name'], strrpos($_FILES['BLOCKSTORE_IMG']['name'], '.') + 1);
                 $file_name = md5($_FILES['BLOCKSTORE_IMG']['name']) . '.' . $ext;
                 if (!move_uploaded_file($_FILES['BLOCKSTORE_IMG']['tmp_name'], dirname(__FILE__) . '/' . $file_name)) {
                     return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
                 } else {
                     if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $file_name) {
                         @unlink(dirname(__FILE__) . '/' . Configuration::get('BLOCKSTORE_IMG'));
                     }
                     Configuration::updateValue('BLOCKSTORE_IMG', $file_name);
                     $this->_clearCache('blockstore.tpl');
                     return $this->displayConfirmation($this->l('The settings have been updated.'));
                 }
             }
         }
         $this->_clearCache('blockstore.tpl');
     }
     return '';
 }
開發者ID:jpodracky,項目名稱:dogs,代碼行數:33,代碼來源:blockstore.php

示例3: validate

 protected function validate(&$file)
 {
     $file['error'] = $this->checkUploadError($file['error']);
     if ($file['error']) {
         return false;
     }
     $post_max_size = Tools::convertBytes(ini_get('post_max_size'));
     $upload_max_filesize = Tools::convertBytes(ini_get('upload_max_filesize'));
     if ($post_max_size && $this->_getServerVars('CONTENT_LENGTH') > $post_max_size) {
         $file['error'] = Tools::displayError('The uploaded file exceeds the post_max_size directive in php.ini');
         return false;
     }
     if ($upload_max_filesize && $this->_getServerVars('CONTENT_LENGTH') > $upload_max_filesize) {
         $file['error'] = Tools::displayError('The uploaded file exceeds the upload_max_filesize directive in php.ini');
         return false;
     }
     if ($error = ImageManager::validateUpload($file, Tools::getMaxUploadSize($this->getMaxSize()), $this->getAcceptTypes())) {
         $file['error'] = $error;
         return false;
     }
     if ($file['size'] > $this->getMaxSize()) {
         $file['error'] = sprintf(Tools::displayError('File (size : %1s) is too big (max : %2s)'), $file['size'], $this->getMaxSize());
         return false;
     }
     return true;
 }
開發者ID:prestanesia,項目名稱:PrestaShop,代碼行數:26,代碼來源:HelperImageUploader.php

示例4: postProcess

 public function postProcess()
 {
     if (Tools::isSubmit('submitStoreConf')) {
         Configuration::updateValue('PRODUCTPAYMENTLOGOS_LINK', Tools::getValue('PRODUCTPAYMENTLOGOS_LINK'));
         Configuration::updateValue('PRODUCTPAYMENTLOGOS_TITLE', Tools::getValue('PRODUCTPAYMENTLOGOS_TITLE'));
         if (isset($_FILES['PRODUCTPAYMENTLOGOS_IMG']) && isset($_FILES['PRODUCTPAYMENTLOGOS_IMG']['tmp_name']) && !empty($_FILES['PRODUCTPAYMENTLOGOS_IMG']['tmp_name'])) {
             if (ImageManager::validateUpload($_FILES['PRODUCTPAYMENTLOGOS_IMG'], 4000000)) {
                 return $this->displayError($this->l('Invalid image'));
             } else {
                 $ext = Tools::substr($_FILES['PRODUCTPAYMENTLOGOS_IMG']['name'], Tools::strrpos($_FILES['PRODUCTPAYMENTLOGOS_IMG']['name'], '.') + 1);
                 $file_name = md5($_FILES['PRODUCTPAYMENTLOGOS_IMG']['name']) . '.' . $ext;
                 if (!move_uploaded_file($_FILES['PRODUCTPAYMENTLOGOS_IMG']['tmp_name'], dirname(__FILE__) . '/img/' . $file_name)) {
                     return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
                 } else {
                     $file_path = dirname(__FILE__) . '/img/' . Configuration::get('PRODUCTPAYMENTLOGOS_IMG');
                     if (Configuration::hasContext('PRODUCTPAYMENTLOGOS_IMG', null, Shop::getContext()) && Configuration::get('PRODUCTPAYMENTLOGOS_IMG') != $file_name && file_exists($file_path)) {
                         unlink($file_path);
                     }
                     Configuration::updateValue('PRODUCTPAYMENTLOGOS_IMG', $file_name);
                     $this->_clearCache('productpaymentlogos.tpl');
                     Tools::redirectAdmin('index.php?tab=AdminModules&conf=6&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
                 }
             }
         }
         $this->_clearCache('productpaymentlogos.tpl');
     }
     return '';
 }
開發者ID:WhisperingTree,項目名稱:etagerca,代碼行數:28,代碼來源:productpaymentlogos.php

示例5: validate

 protected function validate(&$file)
 {
     $post_max_size = $this->getPostMaxSizeBytes();
     if ($post_max_size && $this->_getServerVars('CONTENT_LENGTH') > $post_max_size) {
         $file['error'] = Tools::displayError('The uploaded file exceeds the post_max_size directive in php.ini');
         return false;
     }
     if ($error = ImageManager::validateUpload($file, Tools::getMaxUploadSize($this->getMaxSize()), $this->getAcceptTypes())) {
         $file['error'] = $error;
         return false;
     }
     if ($file['size'] > $this->getMaxSize()) {
         $file['error'] = Tools::displayError('File is too big');
         return false;
     }
     return true;
 }
開發者ID:dev-lav,項目名稱:htdocs,代碼行數:17,代碼來源:HelperImageUploader.php

示例6: postProcess

 public function postProcess()
 {
     if (Tools::isSubmit('submitStoreConf')) {
         if (isset($_FILES['store_img']) && isset($_FILES['store_img']['tmp_name']) && !empty($_FILES['store_img']['tmp_name'])) {
             if ($error = ImageManager::validateUpload($_FILES['store_img'], 4000000)) {
                 return $this->displayError($this->l('invalid image'));
             } else {
                 if (!move_uploaded_file($_FILES['store_img']['tmp_name'], dirname(__FILE__) . '/' . $_FILES['store_img']['name'])) {
                     return $this->displayError($this->l('an error occurred on uploading file'));
                 } else {
                     if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $_FILES['store_img']['name']) {
                         @unlink(dirname(__FILE__) . '/' . Configuration::get('BLOCKSTORE_IMG'));
                     }
                     Configuration::updateValue('BLOCKSTORE_IMG', $_FILES['store_img']['name']);
                     return $this->displayConfirmation($this->l('Settings are updated'));
                 }
             }
         }
     }
     return '';
 }
開發者ID:jicheng17,項目名稱:vipinsg,代碼行數:21,代碼來源:blockstore.php

示例7: uploadImage

 protected function uploadImage($id, $name, $dir, $ext = false, $width = null, $height = null)
 {
     if (isset($_FILES[$name]['tmp_name']) && !empty($_FILES[$name]['tmp_name'])) {
         // Delete old image
         if (Validate::isLoadedObject($object = $this->loadObject())) {
             $object->deleteImage();
         } else {
             return false;
         }
         // Check image validity
         $max_size = isset($this->max_image_size) ? $this->max_image_size : 0;
         if ($error = ImageManager::validateUpload($_FILES[$name], Tools::getMaxUploadSize($max_size))) {
             $this->errors[] = $error;
         }
         $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
         if (!$tmp_name) {
             return false;
         }
         if (!move_uploaded_file($_FILES[$name]['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, _PS_MODULE_DIR_ . 'possequence' . DS . 'images' . DS . $name . '_' . $id . '.' . $this->imageType, (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;
         }
         return false;
     }
     return true;
 }
開發者ID:OaSiis,項目名稱:LDDP,代碼行數:40,代碼來源:AdminPossequenceController.php

示例8: postProcess

 public function postProcess()
 {
     if (Tools::isSubmit('submitStoreConf')) {
         if (isset($_FILES['store_img']) && isset($_FILES['store_img']['tmp_name']) && !empty($_FILES['store_img']['tmp_name'])) {
             if ($error = ImageManager::validateUpload($_FILES['store_img'], 4000000)) {
                 return $this->displayError($this->l('Invalid image'));
             } else {
                 if (!move_uploaded_file($_FILES['store_img']['tmp_name'], dirname(__FILE__) . '/' . $_FILES['store_img']['name'])) {
                     return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
                 } else {
                     if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $_FILES['store_img']['name']) {
                         @unlink(dirname(__FILE__) . '/' . Configuration::get('BLOCKSTORE_IMG'));
                     }
                     Configuration::updateValue('BLOCKSTORE_IMG', $_FILES['store_img']['name']);
                     $this->_clearCache('blockstore.tpl');
                     return $this->displayConfirmation($this->l('The settings have been updated.'));
                 }
             }
         }
     }
     return '';
 }
開發者ID:FAVHYAN,項目名稱:a3workout,代碼行數:22,代碼來源:blockstore.php

示例9: updateLogo

 /**
  * Generic function which allows logo upload
  *
  * @param $field_name
  * @param $logo_prefix
  *
  * @return bool
  */
 protected function updateLogo($field_name, $logo_prefix)
 {
     $id_shop = Context::getContext()->shop->id;
     if (isset($_FILES[$field_name]['tmp_name']) && $_FILES[$field_name]['tmp_name']) {
         if ($error = ImageManager::validateUpload($_FILES[$field_name], Tools::getMaxUploadSize())) {
             $this->errors[] = $error;
             return false;
         }
         $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
         if (!$tmp_name || !move_uploaded_file($_FILES[$field_name]['tmp_name'], $tmp_name)) {
             return false;
         }
         $ext = $field_name == 'PS_STORES_ICON' ? '.gif' : '.jpg';
         $logo_name = Tools::link_rewrite(Context::getContext()->shop->name) . '-' . Configuration::get('PS_IMG_UPDATE_TIME') . '-' . (int) $id_shop . $ext;
         if (Context::getContext()->shop->getContext() == Shop::CONTEXT_ALL || $id_shop == 0 || Shop::isFeatureActive() == false) {
             $logo_name = Tools::link_rewrite(Context::getContext()->shop->name) . '-' . Configuration::get('PS_IMG_UPDATE_TIME') . $ext;
         }
         if ($field_name == 'PS_STORES_ICON') {
             if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name, null, null, 'gif', true)) {
                 $this->errors[] = Tools::displayError('An error occurred while attempting to copy your logo.');
             }
         } else {
             if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name)) {
                 $this->errors[] = Tools::displayError('An error occurred while attempting to copy your logo.');
             }
         }
         if (!count($this->errors) && @filemtime(_PS_IMG_DIR_ . Configuration::get($field_name))) {
             @unlink(_PS_IMG_DIR_ . Configuration::get($field_name));
         }
         Configuration::updateValue($field_name, $logo_name);
         @unlink($tmp_name);
     }
 }
開發者ID:dev-lav,項目名稱:htdocs,代碼行數:41,代碼來源:AdminThemesController.php

示例10: ajaxProcessUpdateCustomizationFields

 public function ajaxProcessUpdateCustomizationFields()
 {
     $errors = array();
     if ($this->tabAccess['edit'] === '1') {
         $errors = array();
         if (Tools::getValue('only_display') != 1) {
             if (!$this->context->cart->id || !($id_product = (int) Tools::getValue('id_product'))) {
                 return;
             }
             $product = new Product((int) $id_product);
             if (!($customization_fields = $product->getCustomizationFieldIds())) {
                 return;
             }
             foreach ($customization_fields as $customization_field) {
                 $field_id = 'customization_' . $id_product . '_' . $customization_field['id_customization_field'];
                 if ($customization_field['type'] == Product::CUSTOMIZE_TEXTFIELD) {
                     if (!Tools::getValue($field_id)) {
                         if ($customization_field['required']) {
                             $errors[] = Tools::displayError('Please fill in all the required fields.');
                         }
                         continue;
                     }
                     if (!Validate::isMessage(Tools::getValue($field_id))) {
                         $errors[] = Tools::displayError('Invalid message');
                     }
                     $this->context->cart->addTextFieldToProduct((int) $product->id, (int) $customization_field['id_customization_field'], Product::CUSTOMIZE_TEXTFIELD, Tools::getValue($field_id));
                 } elseif ($customization_field['type'] == Product::CUSTOMIZE_FILE) {
                     if (!isset($_FILES[$field_id]) || !isset($_FILES[$field_id]['tmp_name']) || empty($_FILES[$field_id]['tmp_name'])) {
                         if ($customization_field['required']) {
                             $errors[] = Tools::displayError('Please fill in all the required fields.');
                         }
                         continue;
                     }
                     if ($error = ImageManager::validateUpload($_FILES[$field_id], (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'))) {
                         $errors[] = $error;
                     }
                     if (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES[$field_id]['tmp_name'], $tmp_name)) {
                         $errors[] = Tools::displayError('An error occurred during the image upload process.');
                     }
                     $file_name = md5(uniqid(rand(), true));
                     if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name)) {
                         continue;
                     } elseif (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name . '_small', (int) Configuration::get('PS_PRODUCT_PICTURE_WIDTH'), (int) Configuration::get('PS_PRODUCT_PICTURE_HEIGHT'))) {
                         $errors[] = Tools::displayError('An error occurred during the image upload process.');
                     } elseif (!chmod(_PS_UPLOAD_DIR_ . $file_name, 0777) || !chmod(_PS_UPLOAD_DIR_ . $file_name . '_small', 0777)) {
                         $errors[] = Tools::displayError('An error occurred during the image upload process.');
                     } else {
                         $this->context->cart->addPictureToProduct((int) $product->id, (int) $customization_field['id_customization_field'], Product::CUSTOMIZE_FILE, $file_name);
                     }
                     unlink($tmp_name);
                 }
             }
         }
         $this->setMedia();
         $this->initFooter();
         $this->context->smarty->assign(array('customization_errors' => implode('<br />', $errors), 'css_files' => $this->css_files));
         return $this->smartyOutputContent('controllers/orders/form_customization_feedback.tpl');
     }
 }
開發者ID:zangles,項目名稱:lennyba,代碼行數:59,代碼來源:AdminCartsController.php

示例11: processUploadLogo

 /**
  * Process the upload of new logo
  */
 public function processUploadLogo()
 {
     $error = '';
     if (isset($_FILES['fileToUpload']['tmp_name']) && $_FILES['fileToUpload']['tmp_name']) {
         $file = $_FILES['fileToUpload'];
         $error = ImageManager::validateUpload($file, 300000);
         if (!strlen($error)) {
             $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
             if (!$tmp_name || !move_uploaded_file($file['tmp_name'], $tmp_name)) {
                 return false;
             }
             list($width, $height, $type) = getimagesize($tmp_name);
             $newheight = $height > 500 ? 500 : $height;
             $percent = $newheight / $height;
             $newwidth = $width * $percent;
             $newheight = $height * $percent;
             if (!is_writable(_PS_ROOT_DIR_ . '/img/')) {
                 $error = $this->l('Image folder %s is not writable', _PS_ROOT_DIR_ . '/img/');
             }
             if (!$error) {
                 list($src_width, $src_height, $type) = getimagesize($tmp_name);
                 $src_image = ImageManager::create($type, $tmp_name);
                 $dest_image = imagecreatetruecolor($src_width, $src_height);
                 $white = imagecolorallocate($dest_image, 255, 255, 255);
                 imagefilledrectangle($dest_image, 0, 0, $src_width, $src_height, $white);
                 imagecopyresampled($dest_image, $src_image, 0, 0, 0, 0, $src_width, $src_height, $src_width, $src_height);
                 if (!imagejpeg($dest_image, _PS_ROOT_DIR_ . '/img/logo.jpg', 95)) {
                     $error = $this->l('An error occurred during logo copy.');
                 } else {
                     imagedestroy($dest_image);
                     @chmod($filename, 0664);
                 }
             }
         } else {
             $error = $this->l('An error occurred during logo upload.');
         }
     }
     $this->ajaxJsonAnswer($error ? false : true, $error);
 }
開發者ID:FAVHYAN,項目名稱:a3workout,代碼行數:42,代碼來源:configure.php

示例12: getContent

 public function getContent()
 {
     $html = '';
     $id_reinsurance = (int) Tools::getValue('id_reinsurance');
     if (Tools::isSubmit('saveblockreinsurance')) {
         if ($id_reinsurance = Tools::getValue('id_reinsurance')) {
             $reinsurance = new reinsuranceClass((int) $id_reinsurance);
         } else {
             $reinsurance = new reinsuranceClass();
         }
         $reinsurance->copyFromPost();
         $reinsurance->id_shop = $this->context->shop->id;
         if ($reinsurance->validateFields(false) && $reinsurance->validateFieldsLang(false)) {
             $reinsurance->save();
             if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) {
                 if ($error = ImageManager::validateUpload($_FILES['image'])) {
                     return false;
                 } elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) {
                     return false;
                 } elseif (!ImageManager::resize($tmpName, dirname(__FILE__) . '/img/reinsurance-' . (int) $reinsurance->id . '-' . (int) $reinsurance->id_shop . '.jpg')) {
                     return false;
                 }
                 unlink($tmpName);
                 $reinsurance->file_name = 'reinsurance-' . (int) $reinsurance->id . '-' . (int) $reinsurance->id_shop . '.jpg';
                 $reinsurance->save();
             }
             $this->_clearCache('blockreinsurance.tpl');
         } else {
             $html .= '<div class="conf error">' . $this->l('An error occurred while attempting to save.') . '</div>';
         }
     }
     if (Tools::isSubmit('updateblockreinsurance') || Tools::isSubmit('addblockreinsurance')) {
         $helper = $this->initForm();
         foreach (Language::getLanguages(false) as $lang) {
             if ($id_reinsurance) {
                 $reinsurance = new reinsuranceClass((int) $id_reinsurance);
                 $helper->fields_value['text'][(int) $lang['id_lang']] = $reinsurance->text[(int) $lang['id_lang']];
             } else {
                 $helper->fields_value['text'][(int) $lang['id_lang']] = Tools::getValue('text_' . (int) $lang['id_lang'], '');
             }
         }
         if ($id_reinsurance = Tools::getValue('id_reinsurance')) {
             $this->fields_form[0]['form']['input'][] = array('type' => 'hidden', 'name' => 'id_reinsurance');
             $helper->fields_value['id_reinsurance'] = (int) $id_reinsurance;
         }
         return $html . $helper->generateForm($this->fields_form);
     } else {
         if (Tools::isSubmit('deleteblockreinsurance')) {
             $reinsurance = new reinsuranceClass((int) $id_reinsurance);
             if (file_exists(dirname(__FILE__) . '/img/' . $reinsurance->file_name)) {
                 unlink(dirname(__FILE__) . '/img/' . $reinsurance->file_name);
             }
             $reinsurance->delete();
             $this->_clearCache('blockreinsurance.tpl');
             Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
         } else {
             $helper = $this->initList();
             return $html . $helper->generateList($this->getListContent((int) Configuration::get('PS_LANG_DEFAULT')), $this->fields_list);
         }
     }
     if (isset($_POST['submitModule'])) {
         Configuration::updateValue('BLOCKREINSURANCE_NBBLOCKS', isset($_POST['nbblocks']) && $_POST['nbblocks'] != '' ? (int) $_POST['nbblocks'] : '');
         if ($this->removeFromDB() && $this->addToDB()) {
             $this->_clearCache('blockreinsurance.tpl');
             $output = '<div class="conf confirm">' . $this->l('The block configuration has been updated.') . '</div>';
         } else {
             $output = '<div class="conf error"><img src="../img/admin/disabled.gif"/>' . $this->l('An error occurred while attempting to save.') . '</div>';
         }
     }
 }
開發者ID:informaticapb,項目名稱:Prestashop,代碼行數:70,代碼來源:blockreinsurance.php

示例13: _postProcess

 private function _postProcess()
 {
     $errors = array();
     /* Process Slide status */
     if (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) {
         $slide = new leftBanner((int) Tools::getValue('id_slide'));
         if ($slide->active == 0) {
             $slide->active = 1;
         } else {
             $slide->active = 0;
         }
         $res = $slide->update();
         $this->clearCache();
         $this->html .= $res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.'));
     } elseif (Tools::isSubmit('submitSlide')) {
         /* Sets ID if needed */
         if (Tools::getValue('id_slide')) {
             $slide = new leftBanner((int) Tools::getValue('id_slide'));
             if (!Validate::isLoadedObject($slide)) {
                 $this->html .= $this->displayError($this->l('Invalid id_slide'));
                 return false;
             }
         } else {
             $slide = new leftBanner();
         }
         /* Sets position */
         $slide->position = (int) Tools::getValue('position');
         /* Sets active */
         $slide->active = (int) Tools::getValue('active_slide');
         /* Sets each langue fields */
         $languages = Language::getLanguages(false);
         foreach ($languages as $language) {
             $slide->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']);
             $slide->url[$language['id_lang']] = Tools::getValue('url_' . $language['id_lang']);
             /* Uploads image and sets slide */
             $type = Tools::strtolower(Tools::substr(strrchr($_FILES['image_' . $language['id_lang']]['name'], '.'), 1));
             $imagesize = @getimagesize($_FILES['image_' . $language['id_lang']]['tmp_name']);
             if (isset($_FILES['image_' . $language['id_lang']]) && isset($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($imagesize) && in_array(Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) {
                 $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
                 $salt = sha1(microtime());
                 if ($error = ImageManager::validateUpload($_FILES['image_' . $language['id_lang']])) {
                     $errors[] = $error;
                 } elseif (!$temp_name || !move_uploaded_file($_FILES['image_' . $language['id_lang']]['tmp_name'], $temp_name)) {
                     return false;
                 } elseif (!ImageManager::resize($temp_name, dirname(__FILE__) . '/img/' . Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type, null, null, $type)) {
                     $errors[] = $this->displayError($this->l('An error occurred during the image upload process.'));
                 }
                 if (isset($temp_name)) {
                     @unlink($temp_name);
                 }
                 $slide->image[$language['id_lang']] = Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type;
             } elseif (Tools::getValue('image_old_' . $language['id_lang']) != '') {
                 $slide->image[$language['id_lang']] = Tools::getValue('image_old_' . $language['id_lang']);
             }
         }
         /* Processes if no errors  */
         if (!$errors) {
             /* Adds */
             if (!Tools::getValue('id_slide')) {
                 if (!$slide->add()) {
                     $errors[] = $this->displayError($this->l('The slide could not be added.'));
                 }
             } elseif (!$slide->update()) {
                 $errors[] = $this->displayError($this->l('The slide could not be updated.'));
             }
             $this->clearCache();
         }
     } elseif (Tools::isSubmit('delete_id_slide')) {
         $slide = new leftBanner((int) Tools::getValue('delete_id_slide'));
         $res = $slide->delete();
         $this->clearCache();
         if (!$res) {
             $this->html .= $this->displayError('Could not delete.');
         } else {
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=1&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
         }
     }
     /* Display errors if needed */
     if (count($errors)) {
         $this->html .= $this->displayError(implode('<br />', $errors));
     } elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide')) {
         Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
     } elseif (Tools::isSubmit('submitSlide')) {
         Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
     }
 }
開發者ID:IngenioContenidoDigital,項目名稱:serta,代碼行數:86,代碼來源:tmleftbanner.php

示例14: processImageUpload

 public function processImageUpload($FILES)
 {
     if (isset($FILES['avatar']) && isset($FILES['avatar']['tmp_name']) && !empty($FILES['avatar']['tmp_name'])) {
         if (ImageManager::validateUpload($FILES['avatar'], 4000000)) {
             return $this->displayError($this->l('Invalid image'));
         } else {
             $ext = Tools::substr($FILES['avatar']['name'], strrpos($FILES['avatar']['name'], '.') + 1);
             $file_name = 'avatar.' . $ext;
             $path = _PS_MODULE_DIR_ . 'smartblog/images/avatar/' . $file_name;
             if (!move_uploaded_file($FILES['avatar']['tmp_name'], $path)) {
                 return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
             } else {
                 $author_types = BlogImageType::GetImageAllType('author');
                 foreach ($author_types as $image_type) {
                     $dir = _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . Tools::stripslashes($image_type['type_name']) . '.jpg';
                     if (file_exists($dir)) {
                         unlink($dir);
                     }
                 }
                 $images_types = BlogImageType::GetImageAllType('author');
                 foreach ($images_types as $image_type) {
                     ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . Tools::stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
                 }
             }
         }
     }
 }
開發者ID:johnulist,項目名稱:smartblog,代碼行數:27,代碼來源:smartblog.php

示例15: getContent

 /**
  * render content info
  */
 public function getContent()
 {
     //        $resultCheck = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT `id_btmegamenu` as id FROM `' . _DB_PREFIX_ . 'btmegamenu_shop` WHERE `id_btmegamenu` = 1 AND `id_shop`=' . (int) ($this->context->shop->id));
     //        if ($resultCheck["id"] != 1){
     //            Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'btmegamenu_shop`(`id_btmegamenu`,`id_shop`) VALUES( 1, '.(int)$this->context->shop->id.' )');
     //        }
     $output = '';
     $this->_html .= $this->headerHTML();
     $this->_html .= '<h2>' . $this->displayName . '.</h2>';
     /* update tree megamenu positions */
     if (Tools::getValue('doupdatepos') && Tools::isSubmit('updatePosition')) {
         $list = Tools::getValue('list');
         $root = 1;
         $child = array();
         foreach ($list as $id => $parent_id) {
             if ($parent_id <= 0) {
                 # validate module
                 $parent_id = $root;
             }
             $child[$parent_id][] = $id;
         }
         $res = true;
         foreach ($child as $id_parent => $menus) {
             $i = 0;
             foreach ($menus as $id_btmegamenu) {
                 $res &= Db::getInstance()->execute('
                     UPDATE `' . _DB_PREFIX_ . 'btmegamenu` SET `position` = ' . (int) $i . ', id_parent = ' . (int) $id_parent . ' 
                     WHERE `id_btmegamenu` = ' . (int) $id_btmegamenu);
                 $i++;
             }
         }
         $this->clearCache();
         die($this->l('Update Positions Done'));
     }
     if (Tools::getValue('show_cavas') && Tools::isSubmit('updatecavas')) {
         $show = Tools::getValue('show') ? Tools::getValue('show') : 0;
         if (Configuration::updateValue('LEO_MEGAMENU_CAVAS', $show)) {
             $this->clearCache();
             die($this->l('Update Done'));
         } else {
             die($this->l('Can not Update'));
         }
     }
     /* delete megamenu item */
     if (Tools::getValue('dodel')) {
         $obj = new Btmegamenu((int) Tools::getValue('id_btmegamenu'));
         $res = $obj->delete();
         $this->clearCache();
         Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
     }
     if (Tools::isSubmit('save' . $this->name) && Tools::isSubmit('active')) {
         // if( Tools::getValue('type') == 'url' && !Tools::getValue('url')){
         //              $errors[] = $this->l('Account details are required.');
         //          }
         //			if (!isset($errors) AND !sizeof($errors)){
         if ($id_btmegamenu = Tools::getValue('id_btmegamenu')) {
             # validate module
             $megamenu = new Btmegamenu((int) $id_btmegamenu);
         } else {
             # validate module
             $megamenu = new Btmegamenu();
         }
         $keys = LeoBtmegamenuHelper::getConfigKey(false);
         $post = LeoBtmegamenuHelper::getPost($keys, false);
         $keys = LeoBtmegamenuHelper::getConfigKey(true);
         $post += LeoBtmegamenuHelper::getPost($keys, true);
         $megamenu->copyFromPost($post);
         $megamenu->id_shop = $this->context->shop->id;
         if ($megamenu->type && $megamenu->type != 'html' && Tools::getValue($megamenu->type . '_type')) {
             # validate module
             $megamenu->item = Tools::getValue($megamenu->type . '_type');
         }
         $url_default = '';
         foreach ($megamenu->url as $menu_url) {
             if ($menu_url) {
                 $url_default = $menu_url;
                 break;
             }
         }
         if ($url_default) {
             foreach ($megamenu->url as &$menu_url) {
                 if (!$menu_url) {
                     $menu_url = $url_default;
                 }
             }
         }
         if ($megamenu->validateFields(false) && $megamenu->validateFieldsLang(false)) {
             $megamenu->save();
             if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) {
                 $this->checkFolderIcon();
                 if (ImageManager::validateUpload($_FILES['image'])) {
                     return false;
                 } elseif (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmp_name)) {
                     return false;
                 } elseif (!ImageManager::resize($tmp_name, $this->img_path . $_FILES['image']['name'])) {
                     return false;
                 }
//.........這裏部分代碼省略.........
開發者ID:evgrishin,項目名稱:mh16014,代碼行數:101,代碼來源:leobootstrapmenu.php


注:本文中的ImageManager::validateUpload方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。