示例#1
0
文件: photo.php 项目: 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));
 }
示例#2
0
 /**
  * Index method to serve a file
  *
  * @return null
  */
 public function action_index($photo = NULL)
 {
     $photo = new Model_Vendo_Photo($photo);
     if (!$photo->id) {
         throw new Vendo_404('Photo not found');
     }
     $path_info = pathinfo($photo->path() . $photo->filename);
     $ext = $path_info['extension'];
     header('Content-Type: image/' . $path_info['extension']);
     header('Content-Length: ' . filesize($photo->path() . $photo->filename));
     readfile($photo->path() . $photo->filename);
     die;
 }
示例#3
0
文件: photo.php 项目: vendo/admin
 /**
  * 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');
     }
 }