Exemple #1
0
 /**
  * Validate file and add to database.
  *
  * @param string $absoluteFileName
  * @param string $url
  *
  * @return boolean
  */
 protected function importFromFile($absoluteFileName)
 {
     $model = null;
     try {
         $imageType = @exif_imagetype($absoluteFileName);
         if ($imageType === false) {
             Log::error('Could not read image type for feed item image ' . $this->url);
             return false;
         }
         if (!in_array($imageType, $this->validImageTypes)) {
             Log::error('Invalid image type for feed item image ' . $this->url . ': ' . $imageType);
             return false;
         }
         if (!@rename($absoluteFileName, $absoluteFileName . '.' . image_type_to_extension($imageType, false))) {
             Log::error('Could not rename downloaded feed item image ' . $absoluteFileName);
             return false;
         }
         $absoluteFileName = $absoluteFileName . '.' . image_type_to_extension($imageType, false);
         $fileInfo = new UploadedFile($absoluteFileName, basename($absoluteFileName), image_type_to_mime_type($imageType), filesize($absoluteFileName));
         $model = Image::createFromUpload($fileInfo, $this->feed->user_id);
     } catch (\Exception $e) {
         Log::error('Could not upload feed item image: ' . $e->getMessage() . '(' . $e->getFile() . ' - Line:' . $e->getLine() . ')');
         if ($model !== null) {
             $model->delete();
         }
         return false;
     } finally {
         @unlink($absoluteFileName);
     }
     $this->image_id = $model->id;
     return true;
 }
 /**
  * Upload the image.
  *
  * @return Response
  */
 public function upload(Request $request)
 {
     if (!$request->file('file')->isValid()) {
         abort(400, 'Invalid file!');
     }
     $raw = $request->file('file');
     // Create model
     $model = Image::createFromUpload($raw, Sentinel::getUser()->id);
     return;
 }