Advertisement
Guest User

Untitled

a guest
May 6th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. protected function uploadImage($id, $name, $dir, $ext = false, $width = null, $height = null)
  2. {
  3. if (isset($_FILES[$name]['tmp_name']) && !empty($_FILES[$name]['tmp_name']))
  4. {
  5. // Delete old image
  6. if (Validate::isLoadedObject($object = $this->loadObject()))
  7. $object->deleteImage();
  8. else
  9. return false;
  10.  
  11. // Check image validity
  12. $max_size = isset($this->max_image_size) ? $this->max_image_size : 0;
  13. if ($error = ImageManager::validateUpload($_FILES[$name], Tools::getMaxUploadSize($max_size)))
  14. $this->errors[] = $error;
  15.  
  16. $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
  17. if (!$tmp_name)
  18. return false;
  19.  
  20. if (!move_uploaded_file($_FILES[$name]['tmp_name'], $tmp_name))
  21. return false;
  22.  
  23. // Evaluate the memory required to resize the image: if it's too much, you can't resize it.
  24. if (!ImageManager::checkImageMemoryLimit($tmp_name))
  25. $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. ');
  26.  
  27. // Copy new image
  28. if (empty($this->errors) && !ImageManager::resize($tmp_name, _PS_IMG_DIR_.$dir.$id.'.'.$this->imageType, (int)$width, (int)$height, ($ext ? $ext : $this->imageType)))
  29. $this->errors[] = Tools::displayError('An error occurred while uploading the image.');
  30.  
  31. if (count($this->errors))
  32. return false;
  33. if ($this->afterImageUpload())
  34. {
  35. unlink($tmp_name);
  36. return true;
  37. }
  38. return false;
  39. }
  40. return true;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement