0

Hi I have a script to download images using url. The url is in csv file. There are a lot of images which need to be downloaded at least 200k. The problem is when downloading some images it has permission denied issue. I have no problem with that if the image have permission issue I dont want to download but it makes the php script too slow. It takes lots of time to download images. Any suggestion how to download images faster and avoid images which has permission denied issue. Is downloading images with python is more faster than php. Below is the code i use to download images.

<?php


$csv_file = 'bags_import_images.csv';
$handle = fopen($csv_file, "r");
$destination = 'images_import/';
$time = 0;
if ($handle) {
    while ($columns = fgetcsv($handle)) {
        foreach ($columns as $imageUrl) 
        {
            if (!empty($imageUrl)) 
            {
                file_put_contents(
                $destination. basename($imageUrl),
                file_get_contents($imageUrl)
            );
        }
        echo $time++;
    }
}
}

?>
aynber
  • 22,380
  • 8
  • 50
  • 63
  • I suggest you to use [Curl with connection time out](https://stackoverflow.com/questions/2582057/setting-curls-timeout-in-php) to make it faster if target URL is unable to connect. The download speed is depend on your server connection speed and target server connection speed. You can use [Curl to download file](https://stackoverflow.com/questions/6409462/downloading-a-large-file-using-curl), please see the example on the link. – vee Nov 11 '21 at 07:29
  • 2
    _"and avoid images which has permission denied issue"_ - you can not "avoid" making that request to begin with, because otherwise you would not *know* that you don't have permission ... – CBroe Nov 11 '21 at 07:43
  • @CBroe , yes i m using curl for that – nazmul mondal Nov 13 '21 at 13:06

0 Answers0