Jump to content

php script for download

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
yamaguchi

yamaguchi

    Newbie

  • Members
  • PipPip
  • 12 posts
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!

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
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.

#3
yamaguchi

yamaguchi

    Newbie

  • Members
  • PipPip
  • 12 posts
how?

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
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.

#5
yamaguchi

yamaguchi

    Newbie

  • Members
  • PipPip
  • 12 posts
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
Arctic Fire

Arctic Fire

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
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.

<?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
yamaguchi

yamaguchi

    Newbie

  • Members
  • PipPip
  • 12 posts
Excellent! I think it will serve. Thank you for the script!