Esempio n. 1
0
File: photo.php Progetto: vendo/core
 /**
  * Tests that we can process and read and delete a photo
  * 
  * @return null
  */
 public function test_do_it()
 {
     $photo = new Model_Vendo_Photo();
     $photo->file = DOCROOT . 'media/images/grid.png';
     $photo->save();
     $path = $photo->path() . $photo->filename;
     $this->assertFalse($photo->id === NULL);
     $this->assertTrue(file_exists($path));
     $photo->delete();
     $this->assertFalse(file_exists($path));
 }
Esempio n. 2
0
 /**
  * Processes an uploaded image
  *
  * @return null
  */
 public function action_upload()
 {
     // Validate the upload first
     $validate = new Validate($_FILES);
     $validate->rules('image', array('Upload::not_empty' => null, 'Upload::valid' => null, 'Upload::size' => array('4M'), 'Upload::type' => array(array('jpg', 'png', 'gif'))));
     if ($validate->check(true)) {
         // Shrink the image to the lowest max dimension
         $image = Image::factory($_FILES['image']['tmp_name']);
         $constraints = Kohana::config('image')->constraints;
         $image->resize($constraints['max_width'], $constraints['max_height']);
         $image->save(APPPATH . 'photos/' . $_FILES['image']['name']);
         $photo = new Model_Vendo_Photo();
         $photo->file = APPPATH . 'photos/' . $_FILES['image']['name'];
         $photo->save();
         unlink(APPPATH . 'photos/' . $_FILES['image']['name']);
         $this->request->redirect('admin/photo');
     } else {
         Session::instance()->set('errors', $validate->errors('validate'));
         $this->request->redirect('admin/photo');
     }
 }