-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! :)

4
  • 2
    try to use file_get_contents or curl Commented Sep 9, 2016 at 2: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! Commented Sep 9, 2016 at 2:45
  • lots of samples here on SO stackoverflow.com/questions/22155882/php-curl-download-file stackoverflow.com/questions/1006604/… Commented Sep 9, 2016 at 2: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! :) Commented Sep 9, 2016 at 2:59

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.