HosipLan

Untitled

Apr 11th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1.     /**
  2.      * @param $directory
  3.      * @param $manufacturerId
  4.      * @param $productId
  5.      *
  6.      * @return string
  7.      */
  8.     public function download($directory, $manufacturerId, $productId)
  9.     {
  10.         $extension = pathinfo($this->source, PATHINFO_EXTENSION);
  11.         $title = Nette\Utils\Strings::webalize($this->title);
  12.         $imageName = 'feed_' . $manufacturerId . '.' . $productId . '.' . $title . '.' . $extension;
  13.  
  14.         $try = 3;
  15.         do {
  16.             $targetPath = $directory . '/' . $imageName;
  17.             if (!file_exists($targetPath) && ($imageRaw = @file_get_contents($this->source))) {
  18.                 @file_put_contents($targetPath, $imageRaw);
  19.                 @chmod($targetPath, 0777);
  20.             }
  21.  
  22.             if (FALSE === getimagesize($targetPath)) {
  23.                 unlink($targetPath);
  24.  
  25.             } else {
  26.                 break;
  27.             }
  28.  
  29.         } while($try--);
  30.  
  31.         return $imageName;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment