Beispiel #1
0
 /**
  * Upload a remote file into storage.
  *
  * @param string $url    The url to the remote file to upload.
  * @param string $target The path to the file to store.
  *
  * @return bool
  */
 public function remoteUpload($url, $target)
 {
     $tmp_name = md5($url);
     $tmp_path = Storage::config('tmp_path') . '/' . $tmp_name;
     if (!$this->remoteDownload($url, $tmp_path)) {
         return false;
     }
     return $this->upload($tmp_path, $target);
 }
 /**
  * Index action.
  *
  * @param string $part1
  * @param string $part2
  * 
  * @return mixed
  */
 public function getIndex($part1 = null, $part2 = null)
 {
     $size = empty($part2) ? null : $part1;
     $filename = empty($part2) ? $part1 : $part2;
     if (!($image = Image::where('filename', $filename)->first())) {
         App::abort(404);
     }
     if (!($path = $image->path($size))) {
         App::abort(404);
     }
     return Storage::render($path);
 }
Beispiel #3
0
 public static function copy($path, array $data = array())
 {
     if (!File::exists($path)) {
         return false;
     }
     // Clear file status cache (prevents empty filesize).
     clearstatcache();
     try {
         $resizer = new Resizer($path);
     } catch (Exception $e) {
         return false;
     }
     $image = new static();
     $image->filename = md5(Str::random(32)) . '.' . $resizer->extension();
     $image->original_filename = array_get($data, 'original_filename');
     $image->type = $resizer->mime();
     $image->filesize = File::size($path);
     $image->width = $resizer->width();
     $image->height = $resizer->height();
     $image->ratio = $resizer->ratio();
     if (empty($image->original_filename)) {
         $image->original_filename = basename($path);
         if (false === strstr($image->original_filename, '.')) {
             $image->original_filename .= '.' . $resizer->extension();
         }
     }
     Storage::upload($path, $image->pathFromSize());
     if (!Storage::exists($image->pathFromSize())) {
         return false;
     }
     $image->sizes = array('original' => Storage::url($image->pathFromSize()));
     $image->save();
     return $image;
 }
Beispiel #4
0
<?php

use Dmyers\Storage\Storage;
if ($route_path = Storage::config('route_path', false)) {
    // Register storage route.
    \Route::get($route_path . '{path}', function ($path) {
        try {
            $response = Storage::render($path);
        } catch (\Exception $e) {
            \App::abort(404, 'File not found');
        }
        return $response;
    });
}