* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.3 * */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminAttachments extends AdminTab { protected $maxFileSize = 2000000; public function __construct() { global $cookie; $this->table = 'attachment'; $this->className = 'Attachment'; $this->lang = true; $this->edit = true; $this->delete = true; $this->fieldsDisplay = array( 'id_attachment' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Name')), 'file' => array('title' => $this->l('File'))); parent::__construct(); } public function postProcess() { if (Tools::isSubmit('submitAdd'.$this->table)) { if ($id = intval(Tools::getValue('id_attachment')) AND $a = new Attachment($id)) { $_POST['file'] = $a->file; $_POST['mime'] = $a->mime; } if (!sizeof($this->_errors)) if (isset($_FILES['file']) AND is_uploaded_file($_FILES['file']['tmp_name'])) { if ($_FILES['file']['size'] > $this->maxFileSize) $this->_errors[] = $this->l('File too large, maximum size allowed:').' '.($this->maxFileSize/1000).' '.$this->l('kb'); else { $uploadDir = dirname(__FILE__).'/../../download/'; do $uniqid = sha1(microtime()); while (file_exists($uploadDir.$uniqid)); if (!copy($_FILES['file']['tmp_name'], $uploadDir.$uniqid)) $this->_errors[] = $this->l('File copy failed'); @unlink($_FILES['file']['tmp_name']); $_POST['name_2'] .= '.'.pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); $_POST['file'] = $uniqid; $_POST['mime'] = $_FILES['file']['type']; } } $this->validateRules(); } return parent::postProcess(); } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); $obj = $this->loadObject(true); echo '
'; } } ?>