Skip to content

Instantly share code, notes, and snippets.

Last active October 4, 2018 11:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Some methods for get/leech and save images from url.
* Method 1: use file_put_contents, but it disabled in many shared hosts
$url = "";
file_put_contents("/path/to/folder/" . basename($url), file_get_contents($url));
* Method 2: use file_get_contents, it disabled in many shared hosts too!
$content = file_get_contents("");
$fp = fopen("/path/to/folder/new-image-name.jpg", "w");
fwrite($fp, $content);
* Method 3: use fopen with curl
$ch = curl_init("");
$fp = fopen("/path/to/folder/new-image-name.jpg", "wb");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
* Method 4: use fopen and download images from remote server
$in = fopen("", "rb");
$out = fopen("/path/to/folder/new-image-name.jpg", "wb");
while ($chunk = fread($in,8192)){
fwrite($out, $chunk, 8192);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment