Created
March 24, 2015 00:58
-
-
Save yoelfme/069787879569e124dfaf to your computer and use it in GitHub Desktop.
Upload and Download Files with Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gracias!!!