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;
 }
Example #2
0
 /**
  * Get max file upload size considering server settings and optional max value
  *
  * @param int $max_size optional max file size
  *
  * @return int max file size in bytes
  */
 public static function getMaxUploadSize($max_size = 0)
 {
     $post_max_size = Tools::convertBytes(ini_get('post_max_size'));
     $upload_max_filesize = Tools::convertBytes(ini_get('upload_max_filesize'));
     if ($max_size > 0) {
         $result = min($post_max_size, $upload_max_filesize, $max_size);
     } else {
         $result = min($post_max_size, $upload_max_filesize);
     }
     return $result;
 }
 public function postProcess()
 {
     if (Tools::isSubmit('submitDeleteImgConf')) {
         $this->_deleteCurrentImg();
     }
     $errors = '';
     if (Tools::isSubmit('submitAdvConf')) {
         if (isset($_FILES['adv_img']) && isset($_FILES['adv_img']['tmp_name']) && !empty($_FILES['adv_img']['tmp_name'])) {
             if ($error = ImageManager::validateUpload($_FILES['adv_img'], Tools::convertBytes(ini_get('upload_max_filesize')))) {
                 $errors .= $error;
             } else {
                 Configuration::updateValue('BLOCKADVERT_IMG_EXT', substr($_FILES['adv_img']['name'], strrpos($_FILES['adv_img']['name'], '.') + 1));
                 // Set the image name with a name contextual to the shop context
                 $this->adv_imgname = 'advertising';
                 if (Shop::getContext() == Shop::CONTEXT_GROUP) {
                     $this->adv_imgname = 'advertising-g' . (int) $this->context->shop->getContextShopGroupID();
                 } elseif (Shop::getContext() == Shop::CONTEXT_SHOP) {
                     $this->adv_imgname = 'advertising-s' . (int) $this->context->shop->getContextShopID();
                 }
                 // Copy the image in the module directory with its new name
                 if (!move_uploaded_file($_FILES['adv_img']['tmp_name'], _PS_MODULE_DIR_ . $this->name . '/img/' . $this->adv_imgname . '.' . Configuration::get('BLOCKADVERT_IMG_EXT'))) {
                     $errors .= $this->l('File upload error.');
                 }
             }
         }
         // If the link is not set, then delete it in order to use the next default value (either the global value or the group value)
         if ($link = Tools::getValue('adv_link')) {
             Configuration::updateValue('BLOCKADVERT_LINK', $link);
         } elseif (Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP) {
             Configuration::deleteFromContext('BLOCKADVERT_LINK');
         }
         // If the title is not set, then delete it in order to use the next default value (either the global value or the group value)
         if ($title = Tools::getValue('adv_title')) {
             Configuration::updateValue('BLOCKADVERT_TITLE', $title);
         } elseif (Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP) {
             Configuration::deleteFromContext('BLOCKADVERT_TITLE');
         }
         // Reset the module properties
         $this->initialize();
         $this->_clearCache('blockadvertising.tpl');
         if (!$errors) {
             Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&conf=6');
         }
         echo $this->displayError($errors);
     }
 }
 /**
  * Genrating a export file
  */
 public function generateExport()
 {
     $id = Tools::getValue($this->identifier);
     $export_dir = defined('_PS_HOST_MODE_') ? _PS_ROOT_DIR_ . '/export/' : _PS_ADMIN_DIR_ . '/export/';
     if (!Validate::isFileName($id)) {
         die(Tools::displayError());
     }
     $file = 'request_sql_' . $id . '.csv';
     if ($csv = fopen($export_dir . $file, 'w')) {
         $sql = RequestSql::getRequestSqlById($id);
         if ($sql) {
             $results = Db::getInstance()->executeS($sql[0]['sql']);
             foreach (array_keys($results[0]) as $key) {
                 $tab_key[] = $key;
                 fputs($csv, $key . ';');
             }
             foreach ($results as $result) {
                 fputs($csv, "\n");
                 foreach ($tab_key as $name) {
                     fputs($csv, '"' . strip_tags($result[$name]) . '";');
                 }
             }
             if (file_exists($export_dir . $file)) {
                 $filesize = filesize($export_dir . $file);
                 $upload_max_filesize = Tools::convertBytes(ini_get('upload_max_filesize'));
                 if ($filesize < $upload_max_filesize) {
                     if (Configuration::get('PS_ENCODING_FILE_MANAGER_SQL')) {
                         $charset = Configuration::get('PS_ENCODING_FILE_MANAGER_SQL');
                     } else {
                         $charset = self::$encoding_file[0]['name'];
                     }
                     header('Content-Type: text/csv; charset=' . $charset);
                     header('Cache-Control: no-store, no-cache');
                     header('Content-Disposition: attachment; filename="' . $file . '"');
                     header('Content-Length: ' . $filesize);
                     readfile($export_dir . $file);
                     die;
                 } else {
                     $this->errors[] = Tools::DisplayError('The file is too large and can not be downloaded. Please use the LIMIT clause in this query.');
                 }
             }
         }
     }
 }
 /**
  * postProcess update configuration
  * @TODO adding alt and title attributes for <img> and <a>
  * @var string
  * @return void
  */
 public function postProcess()
 {
     global $currentIndex;
     $errors = '';
     if (Tools::isSubmit('submitDeleteImgConf')) {
         $this->_deleteCurrentImg();
     }
     if (Tools::isSubmit('submitAdvConf')) {
         $file = false;
         if (isset($_FILES['adv_img']) and isset($_FILES['adv_img']['tmp_name']) and !empty($_FILES['adv_img']['tmp_name'])) {
             if ($error = checkImage($_FILES['adv_img'], Tools::convertBytes(ini_get('upload_max_filesize')))) {
                 $errors .= $error;
             } elseif ($dot_pos = strrpos($_FILES['adv_img']['name'], '.')) {
                 // as checkImage tell us it's a good image, we'll just copy the extension
                 $this->_deleteCurrentImg();
                 $this->adv_imgname = 'advertising';
                 $ext = substr($_FILES['adv_img']['name'], $dot_pos + 1);
                 $newname = 'advertising_custom';
                 if (!move_uploaded_file($_FILES['adv_img']['tmp_name'], _PS_MODULE_DIR_ . $this->name . '/' . $newname . '.' . $ext)) {
                     $errors .= $this->l('Error move uploaded file');
                 } else {
                     $this->adv_imgname = $newname;
                 }
                 Configuration::updateValue('BLOCKADVERT_IMG_EXT', $ext);
                 $this->adv_img = Tools::getMediaServer($this->name) . _MODULE_DIR_ . $this->name . '/' . $this->adv_imgname . '.' . Configuration::get('BLOCKADVERT_IMG_EXT');
             }
         }
         if ($link = Tools::getValue('adv_link')) {
             Configuration::updateValue('BLOCKADVERT_LINK', $link);
             $this->adv_link = htmlentities($link, ENT_QUOTES, 'UTF-8');
         }
         if ($title = Tools::getValue('adv_title')) {
             Configuration::updateValue('BLOCKADVERT_TITLE', $title);
             $this->adv_title = htmlentities($title, ENT_QUOTES, 'UTF-8');
         }
     }
     if ($errors) {
         echo $this->displayError($errors);
     }
 }
Example #6
0
//if (substr_count($_SERVER['DOCUMENT_ROOT'], "test"))
//	require_once(_PS_ROOT_DIR_.'/config/settings.inc.test.php');
if (!substr_count($_SERVER['DOCUMENT_ROOT'], "home/matras-house.ru/www")) {
    require_once _PS_ROOT_DIR_ . '/config/settings.inc.php';
} else {
    require_once _PS_ROOT_DIR_ . '/config/settings.inc.dev.php';
}
require_once _PS_CONFIG_DIR_ . 'autoload.php';
if (_PS_DEBUG_PROFILING_) {
    include_once _PS_TOOL_DIR_ . 'profiling/Controller.php';
    include_once _PS_TOOL_DIR_ . 'profiling/ObjectModel.php';
    include_once _PS_TOOL_DIR_ . 'profiling/Hook.php';
    include_once _PS_TOOL_DIR_ . 'profiling/Db.php';
    include_once _PS_TOOL_DIR_ . 'profiling/Tools.php';
}
if (Tools::convertBytes(ini_get('upload_max_filesize')) < Tools::convertBytes('1000M')) {
    ini_set('upload_max_filesize', '1000M');
}
if (Tools::isPHPCLI() && isset($argc) && isset($argv)) {
    Tools::argvToGET($argc, $argv);
}
/* Redefine REQUEST_URI if empty (on some webservers...) */
if (!isset($_SERVER['REQUEST_URI']) || empty($_SERVER['REQUEST_URI'])) {
    if (!isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['SCRIPT_FILENAME'])) {
        $_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_FILENAME'];
    }
    if (isset($_SERVER['SCRIPT_NAME'])) {
        if (basename($_SERVER['SCRIPT_NAME']) == 'index.php' && empty($_SERVER['QUERY_STRING'])) {
            $_SERVER['REQUEST_URI'] = dirname($_SERVER['SCRIPT_NAME']) . '/';
        } else {
            $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];