I need to save an image from a PHP URL to my PC.
Let\'s say I have a page, http://example.com/image.php
, holding a single \"flower\" image, nothing else. How ca
I wasn't able to get any of the other solutions to work, but I was able to use wget:
$tempDir = '/download/file/here';
$finalDir = '/keep/file/here';
$imageUrl = 'http://www.example.com/image.jpg';
exec("cd $tempDir && wget --quiet $imageUrl");
if (!file_exists("$tempDir/image.jpg")) {
throw new Exception('Failed while trying to download image');
}
if (rename("$tempDir/image.jpg", "$finalDir/new-image-name.jpg") === false) {
throw new Exception('Failed while trying to move image file from temp dir to final dir');
}