Last active
January 28, 2016 09:54
-
-
Save m241802/0b5d0a98318304ff08cf to your computer and use it in GitHub Desktop.
create file-object in laravel, use Symfony\Component\HttpFoundation\File\UploadedFile;
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
public function createFileObject($url){ | |
//get name file by url and save in object-file | |
$path_parts = pathinfo($url); | |
//get image info (mime, size in pixel, size in bits) | |
$newPath = $path_parts['dirname'] . '/tmp-files/'; | |
if(!is_dir ($newPath)){ | |
mkdir($newPath, 0777); | |
} | |
$newUrl = $newPath . $path_parts['basename']; | |
copy($url, $newUrl); | |
$imgInfo = getimagesize($newUrl); | |
$file = new UploadedFile( | |
$newUrl, | |
$path_parts['basename'], | |
$imgInfo['mime'], | |
filesize($url), | |
null, | |
TRUE | |
); | |
return $file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment