public function show($id) { $vid = Video::findOrFail($id); $path = env('FILE_UPLOAD_PATH') . '/' . $vid->id . '~' . $vid->upload_filename; $file = File::get($path); return (new Response($file, 200))->header('Content-Type', File::mimeType($path)); }
private function getFileInfos($files, $type = 'Images') { $file_info = []; foreach ($files as $key => $file) { $file_name = parent::getFileName($file)['short']; $file_created = filemtime($file); $file_size = number_format(File::size($file) / 1024, 2, ".", ""); if ($file_size > 1024) { $file_size = number_format($file_size / 1024, 2, ".", "") . " Mb"; } else { $file_size = $file_size . " Kb"; } if ($type === 'Images') { $file_type = File::mimeType($file); $icon = ''; } else { $extension = strtolower(File::extension($file_name)); $icon_array = Config::get('lfm.file_icon_array'); $type_array = Config::get('lfm.file_type_array'); if (array_key_exists($extension, $icon_array)) { $icon = $icon_array[$extension]; $file_type = $type_array[$extension]; } else { $icon = "fa-file"; $file_type = "File"; } } $file_info[$key] = ['name' => $file_name, 'size' => $file_size, 'created' => $file_created, 'type' => $file_type, 'icon' => $icon]; } return $file_info; }
public static function store($files, $material) { // Making counting of uploaded images $file_count = count($files); // start count how many uploaded $uploadcount = 0; if (!empty($files)) { foreach ($files as $file_path) { if (!empty($file_path)) { $type = File::type($file_path); $mime = File::mimeType($file_path); $extension = File::extension($file_path); $filename = $material->slug . '_' . str_replace(' ', '_', File::name($file_path)) . '.' . $extension; File::move($file_path, storage_path() . '/app/' . $filename); //add file path and thumb path to material_files database $material_file = MaterialFile::firstOrCreate(['original_filename' => File::name($file_path), 'filename' => $filename, 'mime' => $mime]); //add to material file table $material->files()->save($material_file); $uploadcount++; //create thumb MaterialFile::makeThumb($extension, $filename); } } if ($uploadcount == $file_count) { Session::flash('success', 'Upload(s) successfully'); } else { return Redirect::to('material.edit')->withInput(); } } }
/** * Get the requested Video File * @param string $fileName * @return Response */ public function video($fileName) { $filePath = storage_path() . '/app/videos/' . $fileName; if (!File::exists($filePath) or !($mimeType = File::mimeType($filePath))) { return response("File does not exist.", 404); } $fileContents = File::get($filePath); return response($fileContents, 200, ['Content-Type' => $mimeType]); }
private function cleanUp() { $files = File::files(storage_path()); foreach ($files as $file) { if (strpos(File::mimeType($file), 'image') != false) { File::delete($file); } } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $mime = File::mimeType(storage_path('app/comprovante_aporte/' . $id)); if (Storage::exists('app/comprovante_aporte/' . $id)) { return 'Arquivo não encontrado'; } $contents = Storage::get('comprovante_aporte/' . $id); return (new Response($contents, 200))->header('Content-Type', 'image/png'); // dd($contents); }
public function getOrganigrama() { $mof = MOF::first(); if ($mof) { $contenido = File::get(public_path() . '/images/' . $mof->organigrama); $tipo_contenido = File::mimeType(public_path() . '/images/' . $mof->organigrama); $respuesta = response($contenido, 200); $respuesta->header('Content-Type', $tipo_contenido); return $respuesta; } // En realidad nunca debería de ocurrir, pero por si acaso return redirect('MOF'); }
public function storeFile($directory, $uploadedFile) { Storage::makeDirectory($directory); if (!$uploadedFile) { return false; } do { $this->file_name = str_random(40); } while (UploadedFile::where('file_name', $this->file_name)->count() > 0); $this->folder = $directory; $this->original_file_name = $uploadedFile->getClientOriginalName(); $uploadedFile->move(storage_path() . $directory, $this->file_name); $this->mime_type = File::mimeType(storage_path() . $directory . $this->file_name); $this->save(); return true; }
public function show_attachment($entity, $entity_id, $type = 'attachment', $file_name = NULL) { switch ($type) { case 'attachment': $path = storage_path() . '/app/' . $entity . '/' . $entity_id . '/attachments/' . $file_name; break; case 'avatar': $file_name = 'avatar.png'; $path = storage_path() . '/app/' . $entity . '/' . $entity_id . '/' . $file_name; break; case 'schedule': $file_name = 'schedule.pdf'; $path = storage_path() . '/app/' . $entity . '/' . $entity_id . '/' . $file_name; break; case 'contract': $file_name = 'contract.pdf'; $path = storage_path() . '/app/' . $entity . '/' . $entity_id . '/' . $file_name; break; case 'evaluations': $file_name = 'evaluations.pdf'; $path = storage_path() . '/app/' . $entity . '/' . $entity_id . '/' . $file_name; break; case 'group_photo': $file_name = 'group_photo.jpg'; $path = storage_path() . '/app/' . $entity . '/' . $entity_id . '/' . $file_name; break; default: $path = storage_path() . '/app/' . $entity . '/' . $entity_id . '/' . $file_name; break; } //dd($path); if (!File::exists($path)) { abort(404); } $file = File::get($path); $type = File::mimeType($path); $response = Response::make($file, 200); $response->header("Content-Type", $type); return $response; }
public function getCvPostulante($id) { $postulante = Postulante::find($id); $contenido = File::get(public_path() . '/curriculums/' . $postulante->cVitae); $tipo_contenido = File::mimeType(public_path() . '/curriculums/' . $postulante->cVitae); $respuesta = response($contenido, 200); $respuesta->header('Content-Type', $tipo_contenido); return $respuesta; }
public function getProfilePics($filename = null) { $path = storage_path('profilepics/' . $filename); if (File::exists($path)) { $file = File::get($path); $type = File::mimeType($path); $response = Response::make($file, 200); $response->header('Content-Type', $type); return $response; } else { $this->generateGravatar(); } }
public function url($filename, $dir = null) { $this->results['filename'] = $filename; $this->results['path'] = rtrim($this->uploadpath, '/') . ($dir ? '/' . trim($dir, '/') : ''); $this->results['dir'] = str_replace(public_path() . '/', '', $this->results['path']); $this->results['filename'] = $filename; $this->results['filepath'] = rtrim($this->results['path']) . '/' . $this->results['filename']; if (File::exists($this->results['filepath'])) { $this->results['filedir'] = str_replace(public_path() . '/', '', $this->results['filepath']); $this->results['basename'] = File::name($this->results['filepath']); $this->results['filesize'] = File::size($this->results['filepath']); $this->results['extension'] = File::extension($this->results['filepath']); $this->results['mime'] = File::mimeType($this->results['filepath']); if ($this->isImage($this->results['mime'])) { list($width, $height) = getimagesize($this->results['filepath']); $this->results['width'] = $width; $this->results['height'] = $height; if (!empty($this->dimensions) && is_array($this->dimensions)) { foreach ($this->dimensions as $name => $dimension) { $suffix = trim($name); $path = $this->results['path'] . ($this->suffix == false ? '/' . trim($suffix, '/') : ''); $name = $this->results['basename'] . ($this->suffix == true ? '_' . trim($suffix, '/') : '') . '.' . $this->results['extension']; $pathname = $path . '/' . $name; if (File::exists($pathname)) { list($nwidth, $nheight) = getimagesize($pathname); $filesize = File::size($pathname); $this->results['dimensions'][$suffix] = ['path' => $path, 'dir' => str_replace(public_path() . '/', '', $path), 'filename' => $name, 'filepath' => $pathname, 'filedir' => str_replace(public_path() . '/', '', $pathname), 'width' => $nwidth, 'height' => $nheight, 'filesize' => $filesize]; } else { $this->results['dimensions'][$suffix] = ['path' => $path, 'dir' => str_replace(public_path() . '/', '', $path), 'filename' => $name, 'filepath' => '#', 'filedir' => '#']; } } } } return new Collection($this->results); } return null; }
/** * Created By Dara on 21/2/2016 * get the video of the session */ public function showVideo($videoName) { $path = storage_path('app') . '/' . $videoName; $file = File::get($path); $type = File::mimeType($path); $headers = ['Content-Type' => 'video/mp4', 'Content-Length' => File::size($path)]; return Response::stream(function () use($path) { try { $stream = fopen($path, 'r'); fpassthru($stream); } catch (Exception $e) { Log::error($e); } }, 200, $headers); }