Skip to content

Instantly share code, notes, and snippets.

@m241802
Last active January 28, 2016 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m241802/0b5d0a98318304ff08cf to your computer and use it in GitHub Desktop.
Save m241802/0b5d0a98318304ff08cf to your computer and use it in GitHub Desktop.
create file-object in laravel, use Symfony\Component\HttpFoundation\File\UploadedFile;
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