Sabbir345's avatar

How to external URL image (download/ copy)

My code

$sourceFilePath = $url;

$destinationPath =public_path()."/uploads/finalAdmitted/";

$success = \File::copy($sourceFilePath,$destinationPath);

0 likes
3 replies
Ricus's avatar

@sabbir345 is the $sourceFilePath a url of an external image that you are trying to copy to your project?

nasirkhan's avatar

You can use file_get_contents() function to fetch the image file.

Please do write more details about the issue, otherwise people will reply based on assumptions. There is a similar question here: https://laracasts.com/discuss/channels/laravel/storing-image-file-retrieved-from-external-url

use Storage;

$url = "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png";
$contents = file_get_contents($url);
$name = substr($url, strrpos($url, '/') + 1);
Storage::put($name, $contents);

Please or to participate in this conversation.