示例#1
0
 public function storeFromUrl($url, $path, $name)
 {
     $counter = 1;
     if (Storage::exists($path . '/' . $name . '.' . pathinfo($url, PATHINFO_EXTENSION))) {
         while (Storage::exists($path . '/' . $name . '-' . $counter . '.' . pathinfo($url, PATHINFO_EXTENSION))) {
             $counter++;
         }
         $name = $name . '-' . $counter;
     }
     $file = file_get_contents($url);
     if (Storage::put($path . '/' . $name . '.' . pathinfo($url, PATHINFO_EXTENSION), $file)) {
         $this->filename = $path . '/' . $name . '.' . pathinfo($url, PATHINFO_EXTENSION);
         $this->mime = Storage::mimeType($path . '/' . $name . '.' . pathinfo($url, PATHINFO_EXTENSION));
         $this->original_filename = $url;
         $this->save();
         return $this->id;
     } else {
         return false;
     }
 }
 /**
  * Return an array of file details for a file
  */
 protected function fileDetails($path)
 {
     $path = '/' . ltrim($path, '/');
     return ['name' => basename($path), 'fullPath' => $path, 'webPath' => $this->fileWebpath($path), 'mimeType' => Storage::mimeType($path), 'size' => $this->fileSize($path), 'modified' => $this->fileModified($path)];
 }
 public function viewFile($name)
 {
     return response()->make(Storage::get($name), 200, ['Content-Type' => Storage::mimeType($name), 'Content-Disposition' => 'inline; ' . $name]);
 }
 public function getImage(Request $request, $image_hash)
 {
     $file = Storage::get('images/' . $image_hash);
     $mimeType = Storage::mimeType('images/' . $image_hash);
     $response = \Illuminate\Support\Facades\Response::make($file, 200);
     $response->header("Content-Type", $mimeType);
     return $response;
 }