pandamasta

Untitled

Dec 30th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. application/classes/Controller/Picture.php
  2. ----------------------------------------------
  3.  
  4. <?php defined('SYSPATH') or die('No direct script access.');
  5.  
  6. class Controller_Picture extends Controller {
  7.  
  8. public function action_index()
  9. {
  10. $view = View::factory('v1/picture/index');
  11. $this->response->body($view);
  12. }
  13.  
  14. public function action_upload()
  15. {
  16. $view = View::factory('v1/picture/upload');
  17. $error_message = NULL;
  18. $filename = NULL;
  19.  
  20. if ($this->request->method() == Request::POST)
  21. {
  22. if (isset($_FILES['avatar']))
  23. {
  24. $filename = $this->_save_image($_FILES['avatar']);
  25. }
  26. }
  27.  
  28. if ( ! $filename)
  29. {
  30. $error_message = 'There was a problem while uploading the image.
  31. Make sure it is uploaded and must be JPG/PNG/GIF file.';
  32. }
  33.  
  34. $view->uploaded_file = $filename;
  35. $view->error_message = $error_message;
  36. $this->response->body($view);
  37. }
  38.  
  39. protected function _save_image($image)
  40. {
  41. if (
  42. ! Upload::valid($image) OR
  43. ! Upload::not_empty($image) OR
  44. ! Upload::type($image, array('jpg', 'jpeg', 'png', 'gif')))
  45. {
  46. return FALSE;
  47. }
  48. Upload::size($image,'1G');
  49. $directory = DOCROOT.'uploads/';
  50.  
  51. if ($file = Upload::save($image, NULL, $directory))
  52. {
  53. $filename = strtolower(Text::random('alnum', 20)).'.jpg';
  54.  
  55. Image::factory($file)
  56. ->resize(200, 200, Image::AUTO)
  57. ->save($directory.$filename);
  58.  
  59. // Delete the temporary file
  60. unlink($file);
  61.  
  62. return $filename;
  63. }
  64.  
  65. return FALSE;
  66. }
  67.  
  68. }
  69.  
  70. ---------------------------------------
  71. php.ini
  72. ---
  73. post_max_size = 8M
  74. upload_max_filesize = 15M
  75.  
  76. nginx
  77. --
  78. client_max_body_size 15M;
Advertisement
Add Comment
Please, Sign In to add comment