Skip to content

Instantly share code, notes, and snippets.

@yoelfme
Created March 24, 2015 00:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoelfme/069787879569e124dfaf to your computer and use it in GitHub Desktop.
Save yoelfme/069787879569e124dfaf to your computer and use it in GitHub Desktop.
Upload and Download Files with Laravel
<?php
/**
* Created by PhpStorm.
* User: yoel
* Date: 8/12/14
* Time: 18:13
*/
namespace App\Helpers;
use Illuminate\Support\Facades\File;
class UploadX {
public static function uploadFile($file,$folder,$name){
$extension = $file->getClientOriginalExtension();
// Verify if directory exists
if (!is_dir($folder))
{
// Create directory
$oldmask = umask(0);
mkdir($folder, 0777);
umask($oldmask);
}
$url = $folder . '/' . $name . '.' . $extension;
if (File::copy($file,$url))
{
return compact('url','extension');
}
else
{
return false;
}
}
public static function downloadFile($file,$name){
$file = public_path() . '/' . $file;
$headers = array();
return response()->download($file,$name,$headers);
}
public static function deleteFile($url)
{
return File::delete($url);
}
}
@rdgutierrez
Copy link

Gracias!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment