Hello!
Someone please help me with a little thing? Hehehe
I need a PHP script to download a file to a folder on my server remotely.
Someone would have a ready there? It can be anyone.
Thanks!
php script for download
Started by yamaguchi, Dec 13 2010 11:16 AM
6 replies to this topic
#1
Posted 13 December 2010 - 11:16 AM
|
|
|
#2
Posted 13 December 2010 - 05:55 PM
Do you mean upload? PHP has an FTP library which can remotely transfer files, you may wish to pass the remote transferring to SSH as well.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 14 December 2010 - 08:58 AM
how?
#4
Posted 14 December 2010 - 05:05 PM
I still would need better wording on what you are wishing to do before I specify any further.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#5
Posted 15 December 2010 - 10:06 AM
I would like to transfer a file from one server to another via a php script. I'm not getting, so I asked for help from the experts. hehehe :c-grin:
#6
Posted 15 December 2010 - 03:52 PM
Do you want the PHP script to upload the file from Server A to Server B? Or do you want the script to run on Server B and download the file from Server A?
Here's a script to download the file from Server A to Server B. Run it on Server B.
If the file isn't accessible using HTTP, you could use FTP. Change the url to something like this:
Here's a script to download the file from Server A to Server B. Run it on Server B.
<?php
// Prevent the script from timing out
set_time_limit(0);
// The url to the file that you want to download
$url = "http://www.example.com/bigfile.zip";
$filename = explode("/",$url);
$filename = $filename[count($filename) - 1];
// Save the downloaded file to this location
$fp = fopen(dirname(__FILE__) . "/{$filename}", 'w+');
// Initialize cURL and tell it to save the request to a file.
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
If the file isn't accessible using HTTP, you could use FTP. Change the url to something like this:
ftp://user:password@site.com/directory/dir2/file.zip
#7
Posted 16 December 2010 - 10:42 AM
Excellent! I think it will serve. Thank you for the script!


Sign In
Create Account


Back to top









