Jump to content

How To Download Files?


rlelek

Recommended Posts

Hey Everyone!

 

I just had a question on how to go about downloading batch files...

 

For Example, I would first create an array of numbers, say 1-1000, and then like for php to download files to a set directory while replacing parts of the following URL with values from the array in a "foreach" loop.

 

$url = "http://www.example.com/*arrayvalue*.*fileextention*"

 

The array could also be words or a combination of words and numbers, but the main thing is...

 

how do I get PHP to download the file from the generated url?

Can that even be done?

 

Thank you!

Link to comment
Share on other sites

Okay, How Would this work?

*It's pretty much all from php.net, so it is not my own..

 

<?php

/* This is the start of the foreach loop*/

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/*filename*.*extention*");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

/* End of Foreach */
?> 

 

But how would i bypass the browser opening and just download the file...

Or.... how could i automatically close the browser after download?

 

 

Link to comment
Share on other sites

well if you are running this like nightly or weekely etc - set the script up as a cron.  If its a download page where you download the file, and then the client downloads from you... hten just do the header() to force the download dialog - and then display a page, even with simple content like:

"Your douwnload should start in 30 seconds... etc etc  "....

 

gdlk

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.