-2

Hi I just want to get an idea on how I can do this.

First. I have a CSV file with links.

Second. I made a code so that all those links are put in one array called $data[].

Third. Now I can Access all the links using the $data[] variable.

Question. How can I make a for loop wherein it opens all the links one by one?

Note. (the links i have, when opened through the browser automatically downloads an image. So I just really need to open each link in the for loop)

I've tried putting it on <a href="$data[]" download>download</a> but i have to click each button just to download the files. Any idea would be a great help thanks! :)

jeeeee
  • 229
  • 1
  • 5
  • 18
  • 2
    try to use `file_get_contents` or `curl` – Kevin Sep 09 '16 at 02:40
  • Thanks for these ideas! I'm currently reading. I'm quite confused though. Specially with curl. If you have time, can you direct me where to look in curl? If not, it's okay at least I got somewhere to start Thanks! – jeeeee Sep 09 '16 at 02:45
  • lots of samples here on SO http://stackoverflow.com/questions/22155882/php-curl-download-file http://stackoverflow.com/questions/1006604/saving-file-using-curl-and-php – Kevin Sep 09 '16 at 02:48
  • Thank you! My problem now is when I get to the first link, it stays there. What I need is for it to loop on all the links. Sorry if i'm being hard to understand! :) – jeeeee Sep 09 '16 at 02:59

1 Answers1

0

You can try this for your purpose. Here you can open the link given in the $data[] without clicking on download link.

For example:

<?php
$data = array(
  'https://www.google.co.in/',
  'http://www.amazon.in/',
  'https://www.flipkart.com/',
);

foreach($data as $key=>$value) { ?>
  <a href="<?php echo $data[$key];?>" id="<?php echo 'test_'.$key;?>" target="_blank">download</a><?php
}
?>

<script type="text/javascript"> 
  for (val = 0; val !== null; val++) {
    var id = document.getElementById('test_'+val);
    document.getElementById('test_'+val).click();
  }
</script>
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57