Add preview from father, add new features
This commit is contained in:
@@ -8,94 +8,157 @@ use Intervention\Image\Facades\Image as Image;
|
||||
|
||||
class Upload
|
||||
{
|
||||
public static function getData($file)
|
||||
{
|
||||
$data['filename'] = $file->getClientOriginalName();
|
||||
$data['filetype'] = $file->extension();
|
||||
$data['filesize'] = $file->getSize();
|
||||
return $data;
|
||||
}
|
||||
public static function getData($file)
|
||||
{
|
||||
$data['filename'] = $file->getClientOriginalName();
|
||||
$data['filetype'] = $file->getClientOriginalExtension();
|
||||
$data['filesize'] = $file->getSize();
|
||||
$data['mime'] = $file->getMimeType();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getUuid($file, $data)
|
||||
{
|
||||
$data = (is_array($data)) ? (object) $data : $data;
|
||||
$pos = strrpos($file, '/');
|
||||
$uuid = substr($file, $pos+1);
|
||||
$uuid = str_replace('.' . $data->filetype, '', $uuid);
|
||||
return $uuid;
|
||||
}
|
||||
public static function getUuid($file, $data)
|
||||
{
|
||||
$data = (is_array($data)) ? (object) $data : $data;
|
||||
$pos = strrpos($file, '/');
|
||||
$uuid = substr($file, $pos+1);
|
||||
$uuid = pathinfo($uuid, PATHINFO_FILENAME);
|
||||
// $uuid = str_replace('.' . strtolower($data->filetype), '', $uuid);
|
||||
// $uuid = str_replace('.' . $data->filetype, '', $uuid);
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
public static function store($file, $filepath)
|
||||
{
|
||||
return $file->store($filepath);
|
||||
}
|
||||
public static function storeByVar($var, $path, $public = false)
|
||||
{
|
||||
// check if filename exists
|
||||
// store
|
||||
// Storage::disk('local')->put('file.txt', 'Contents');
|
||||
// $path = Storage::putFile('avatars', $request->file('avatar'));
|
||||
// $path = $request->file('avatar')->storeAs('avatars',$request->user()->id,'s3');
|
||||
// $path = $request->file('avatar')->storePublicly('avatars', 's3');
|
||||
return $request->has($var) ? basename($request->file($var)->store($path)) : false;
|
||||
}
|
||||
|
||||
public static function storePublic($file, $filepath)
|
||||
{
|
||||
// exit;
|
||||
$filepath = 'public/' . $filepath;
|
||||
return $file->store($filepath);
|
||||
}
|
||||
public static function store($file, $path)
|
||||
{
|
||||
return Storage::putFile($path, $file);
|
||||
// return $file->store($filepath);
|
||||
}
|
||||
|
||||
public static function delete($file)
|
||||
{
|
||||
return Storage::delete($file);
|
||||
}
|
||||
public static function storePublic($file, $filepath)
|
||||
{
|
||||
return Storage::putFile($filepath, $file, 'public');
|
||||
// $filepath = 'public/' . $filepath;
|
||||
// return $file->store($filepath);
|
||||
}
|
||||
|
||||
public static function createThumb($file, $size, $sub = false)
|
||||
{
|
||||
$thumb = self::getThumbPath($file, $sub);
|
||||
$filename = self::getPublicPath($file);
|
||||
return Image::make($filename)->orientate()->widen($size)->save($thumb);
|
||||
}
|
||||
public static function createThumb($file, $size, $sub = false)
|
||||
{
|
||||
$thumb = self::getThumbPath($file, $sub);
|
||||
$filename = self::getPublicPath($file);
|
||||
return Image::make($filename)->orientate()->widen($size)->save($thumb);
|
||||
}
|
||||
|
||||
/*
|
||||
public static function getPath($file) {
|
||||
return 'public/' . self::getFilename($file);
|
||||
}
|
||||
*/
|
||||
|
||||
public static function getPublicPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getFilename($file));
|
||||
}
|
||||
/*
|
||||
public static function getPath($file) {
|
||||
return 'public/' . self::getFilename($file);
|
||||
}
|
||||
*/
|
||||
|
||||
public static function getPublicPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getFilename($file));
|
||||
}
|
||||
|
||||
public static function getPrivatePath($file)
|
||||
{
|
||||
return storage_path('app/' . self::getFilename($file));
|
||||
}
|
||||
public static function getPrivatePath($file)
|
||||
{
|
||||
return storage_path('app/' . self::getFilename($file));
|
||||
}
|
||||
|
||||
public static function getSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getFilename($file);
|
||||
}
|
||||
public static function getSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getFilename($file);
|
||||
}
|
||||
|
||||
public static function getThumbPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getThumbFilename($file));
|
||||
}
|
||||
public static function getThumbPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getThumbFilename($file));
|
||||
}
|
||||
|
||||
public static function getThumbSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getThumbFilename($file);
|
||||
}
|
||||
public static function getThumbSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getThumbFilename($file);
|
||||
}
|
||||
|
||||
public static function getFilename($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . self::getName($file);
|
||||
}
|
||||
public static function getFilename($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . self::getName($file);
|
||||
}
|
||||
|
||||
public static function getThumbFilename($file, $sub = false)
|
||||
{
|
||||
$sub = $sub ? $sub : 'thumbs/';
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . $sub . self::getName($file);
|
||||
}
|
||||
public static function getThumbFilename($file, $sub = false)
|
||||
{
|
||||
$sub = $sub ? $sub : 'thumbs/';
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . $sub . self::getName($file);
|
||||
}
|
||||
|
||||
public static function getName($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->uuid . '.' .$file->filetype;
|
||||
}
|
||||
public static function getName($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->uuid . '.' . strtolower($file->filetype);
|
||||
}
|
||||
|
||||
/**
|
||||
* [fix problem path with Storage on Windows]
|
||||
* @param [type] $path [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function fix($path)
|
||||
{
|
||||
if (self::isWindows()) {
|
||||
return str_replace('/', '\\', $path);
|
||||
} else {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
public static function move($source, $dest)
|
||||
{
|
||||
if (Storage::exists($dest)) {
|
||||
self::delete($dest);
|
||||
}
|
||||
return Storage::move($source, $dest); // transfère et renomme le fichier du dossier temporaire au dossier du client
|
||||
}
|
||||
|
||||
public static function delete($file)
|
||||
{
|
||||
// Storage::delete($file);
|
||||
// return unlink($file);
|
||||
return Storage::delete($file);
|
||||
}
|
||||
|
||||
public static function deleteFile($path)
|
||||
{
|
||||
if (Storage::exists($path)) {
|
||||
return Storage::delete($path);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteRecursive($path)
|
||||
{
|
||||
rmdir_recursive($targetDir);
|
||||
}
|
||||
|
||||
public function make_dir($path, $permissions = 0777)
|
||||
{
|
||||
return is_dir($path) || mkdir($path, $permissions, true);
|
||||
}
|
||||
|
||||
public static function isWindows()
|
||||
{
|
||||
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user