Created
January 4, 2018 12:10
-
-
Save mokoshalb/489a4cc04c4343bf07861ae6908cc9c8 to your computer and use it in GitHub Desktop.
3 ways to download and save a remote image on your server using PHP
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 | |
/* | |
In this tutorial I am going to show you some PHP Methods By which you can easily download remote server image on your local server. | |
Suppose you don't have FTP access of images but you are able to access images via http port and you want to perform bulk image download. | |
Then these methods are very useful and you can try any of them to download and save a remote images on your server folder. | |
*/ | |
// Method-1: By using simple copy() function in PHP | |
copy("REMOTE SERVER IMAGE URL", 'LOCAL SERVER PATH'); | |
// ie: | |
copy("http://example.com/profile.jpg", 'images/profile.jpg'); | |
// Method-2: By using simple file_get_contents() & file_put_contents() function in PHP | |
$content = file_get_contents('http://example.com/profile.jpg'); | |
file_put_contents('images/profile.jpg', $content); | |
// Method-3: By using simple CURL methods in PHP | |
$ch = curl_init('http://example.com/profile.jpg'); | |
$fp = fopen('images/profile.jpg', 'wb'); | |
curl_setopt($ch, CURLOPT_FILE, $fp); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_exec($ch); | |
curl_close($ch); | |
fclose($fp); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment