Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

PHP script to download all images from URL

$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_ENCODING, '' ); // if you're downloading files that benefit from compression (like .bmp images), this line enables compressed transfers.
foreach ( $products as $product ) {

    $url = $product->img;
    $imgName = $product->product_id;
    $path = "images/";

    $img = $path . $imgName . ".png";
    $img=fopen($img,'wb');
    curl_setopt_array ( $ch, array (
            CURLOPT_URL => $url,
            CURLOPT_FILE => $img 
    ) );
    curl_exec ( $ch );
    fclose($img);
    // file_put_contents ( $img, file_get_contents ( $url ) );
}
curl_close ( $ch );
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #PHP #script #download #images #URL
ADD COMMENT
Topic
Name
6+7 =