2017-09-28 18:10:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Common;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Storage;
|
|
|
|
|
|
|
|
class Uploads extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2017-09-28 18:18:37 +03:00
|
|
|
* Get the specified resource.
|
2017-09-28 18:10:13 +03:00
|
|
|
*
|
|
|
|
* @param $folder
|
|
|
|
* @param $file
|
|
|
|
* @return boolean|Response
|
|
|
|
*/
|
2017-09-28 18:18:37 +03:00
|
|
|
public function get($folder, $file)
|
2017-09-28 18:10:13 +03:00
|
|
|
{
|
|
|
|
// Get file path
|
|
|
|
if (!$path = $this->getPath($folder, $file)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->file($path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Download the specified resource.
|
|
|
|
*
|
|
|
|
* @param $folder
|
|
|
|
* @param $file
|
|
|
|
* @return boolean|Response
|
|
|
|
*/
|
|
|
|
public function download($folder, $file)
|
|
|
|
{
|
|
|
|
// Get file path
|
|
|
|
if (!$path = $this->getPath($folder, $file)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->download($path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the full path of resource.
|
|
|
|
*
|
|
|
|
* @param $folder
|
|
|
|
* @param $file
|
|
|
|
* @return boolean|string
|
|
|
|
*/
|
|
|
|
protected function getPath($folder, $file)
|
|
|
|
{
|
|
|
|
// Add company id
|
|
|
|
if ($folder != 'users') {
|
|
|
|
$folder = session('company_id') . '/' . $folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = $folder . '/' . $file;
|
|
|
|
|
|
|
|
if (!Storage::exists($path)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$full_path = Storage::path($path);
|
|
|
|
|
|
|
|
return $full_path;
|
|
|
|
}
|
|
|
|
}
|