Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nympheastudio/af514cbd917c2e6488f44de5b7100557 to your computer and use it in GitHub Desktop.
Save nympheastudio/af514cbd917c2e6488f44de5b7100557 to your computer and use it in GitHub Desktop.
PrestaShop | Image upload
$field_name = 'block_img';
$temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
$salt = sha1(microtime());
$type = strtolower(substr(strrchr($_FILES[$field_name]['name'], '.'), 1));
if ($error = ImageManager::validateUpload($_FILES[$field_name]))
$this->_html .= $this->displayError($error);
elseif (!$temp_name || !move_uploaded_file($_FILES[$field_name]['tmp_name'], $temp_name))
$this->_html .= $this->displayError($this->l('An error occurred during the image upload'));
elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/img/'.$salt.'.'.$type))
$this->_html .= $this->displayError($this->l('An error occurred during the image upload.'));
if (isset($temp_name))
@unlink($temp_name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment