Beispiel #1
0
 public function upload($file, $name)
 {
     try {
         $uploader = new Uploader();
         $uploader->fileTypes(array("gif", "jpg", "jpeg", "png"));
         $uploader->uploadDir('assets/upload');
         $uploader->limitSize(array("min" => 1, "max" => 42000000));
         $fileDir = $uploader->upload($file, $name);
         /* Always use the try/catch block to handle errors */
     } catch (\ImageUploader\ImageUploaderException $e) {
         echo $e->getMessage();
     }
     $image = new Image();
     $image->setImageName($fileDir);
     return $image;
 }
Beispiel #2
0
 /**
  * The thumbnails should be created automatically when first requested
  *
  * This is kind of like the Apache 404 trick, except we're sending
  * all traffic to index.php, so it's handled there, instead of a 404
  */
 public function testAutogenerateThumbnailsByURL()
 {
     $temp = __DIR__ . "/temp.png";
     $zend_db = Database::getConnection();
     $result = $zend_db->query("select * from media where media_type='image' limit 1")->execute();
     if (count($result)) {
         $row = $result->current();
         $media = new Media($row);
         $image = new Image($media);
         $image->clearCache();
         $this->assertFalse(file_exists($image->getFullPathForSize($this->testSize)));
         $url = $image->getURL($this->testSize);
         $request = curl_init($image->getURL($this->testSize));
         curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($request, CURLOPT_BINARYTRANSFER, true);
         file_put_contents($temp, curl_exec($request));
         $this->assertTrue(file_exists($temp));
         $info = getimagesize($temp);
         $this->assertTrue($info[0] == $this->testSize || $info[1] == $this->testSize);
         #if (file_exists($temp)) { unlink($temp); }
     }
 }
Beispiel #3
0
 public function testGenerateAndClearThumbnail()
 {
     copy($this->origFile, $this->testFile);
     $media = new Media();
     $media->setFile($this->FILE);
     $image = new Image($media);
     ob_start();
     $image->output($this->testSize);
     ob_end_clean();
     $newFile = SITE_HOME . "/media/{$media->getDirectory()}/{$media->getInternalFilename()}";
     $thumbnail = SITE_HOME . "/media/{$media->getDirectory()}/{$this->testSize}/{$media->getInternalFilename()}";
     $this->assertTrue(file_exists($thumbnail));
     $info = getimagesize($thumbnail);
     $this->assertTrue($info[0] == $this->testSize || $info[1] == $this->testSize);
     $image->clearCache();
     $this->assertFalse(file_exists($thumbnail));
     if (file_exists($thumbnail)) {
         unlink($thumbnail);
     }
     if (file_exists($newFile)) {
         unlink($newFile);
     }
 }