Briesty Briesty - 6 days ago 5x
PHP Question

In php how can I download images from external website and save into my website?

I am new in php. Recently I am tried to develop a web crawler in order to download images from different server and save into my web server.

Could please help me providing the scripts ?

Thanks for your help


At first create downloadImagesFrmURL function on your scripts as following one:

                  function downloadImagesFrmURL($download_link){

                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, $download_link);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
                    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071127 Firefox/");
                    curl_setopt($ch, CURLINFO_CONTENT_TYPE, "image/jpeg");

                    $data = curl_exec($ch);
                        echo 'error:' . curl_error($ch);

                    return $data;


Above function will help you to download images and return it's data as strings. Once you created above function call it from your php scripts passing the URL you wanted download as follow:

     $data= downloadImagesFrmURL("");


After that use following scripts to save downloaded images to your web server.

  <?php $result = imagecreatefromstring($data);