user3140607
user3140607

Reputation: 303

Download images from specific array of urls with php

I need to download some images from a specific array of urls, something like:

<?php
  $images = array('http://url1.com/img1.png','http://url1.com/img2.png'); 
   // download this images from this paths

I saw some scripts here but don't get them exactly on how can i link them to this array.

The expected output would be: When i run the script to download those images from that array to a specific folder from my server: home/user/public_html/images. It's much appreciated anyone who helps me, i am trying but can't make the connections, currently a rookie.

Upvotes: 1

Views: 3189

Answers (1)

mituw16
mituw16

Reputation: 5250

Something like this maybe.

$images = array('http://ecx.images-amazon.com/images/I/214RgVjsvTL.jpg','http://ecx.images-amazon.com/images/I/515pMJlul8L.jpg'); 

foreach($images as $name=>$image) {

    //get image
    $imageData = file_get_contents($image); //$image variable is the url from your array

    $name = explode("/", $image);

    $handle = fopen("images/".$name[5],"x+");     

    fwrite($handle,$imageData);

    fclose($handle);
}

Upvotes: 1

Related Questions