I want to write a script that will download zip files from a given url and save it somewhere in my hard disk. URL looks like this. http://localhost/downloads/1 to http://localhost/downloads/1. I am trying it like this
<?php
for($i=1;$i<=100;$i++){
$zipfile=file_get_contents('http://localhost/downloads'.$i);
echo $zipfile;}
but it won’t work.
I wanted to try this script on localhost. id will be downloading songs, pics for me.
That’s because your URL are like
http://localhost1,http://localhost2….Notice the missing/.Also to save the downloaded content you use the function
file_put_contentsnotecho. And this needs to be done inside the loop as:Since you’re copying from
localhosttolocalhostyou can better use thecopyfunction.