Jump to content

[SOLVED] Force Download of a remote file on another server, possible?


ThunderAI

Recommended Posts

There is a server that updates a known file every day.  How do I program PHP using header() or another function to go to this website, download the file and place it in a folder for another script to conduct work on it.

 

From what I can see an read about header() that doesn't seem to be able to do what I am looking for.  Is this type of request even possible?

prolly a simpler answer, but here's mine:

<?php
$file = "example.zip"; //the file name
$remote_url = "http://example/"; //the server address (minus the file name)
$local_dir = "/home/user/script/"; //the directory you want the file saved to (absolute path)
/* STOP EDIT */
$full_file = $local_dir.$file;
$command = "/usr/bin/wget $file --output-document=$full_file";
shell_exec($command);
?>

change  $file, $remote_url, and $local_dir, and it will save the file to your desired folder. Next, add it to a cron (ask if you need help w/ that), and it can do it for you automatically.

prolly a simpler answer, but here's mine:

<?php
$file = "example.zip"; //the file name
$remote_url = "http://example/"; //the server address (minus the file name)
$local_dir = "/home/user/script/"; //the directory you want the file saved to (absolute path)
/* STOP EDIT */
$full_file = $local_dir.$file;
$command = "/usr/bin/wget $file --output-document=$full_file";
shell_exec($command);
?>

I tried to execute this on my own localhost to a server i also run, and it wont copy the file and wont give an error either

change  $file, $remote_url, and $local_dir, and it will save the file to your desired folder. Next, add it to a cron (ask if you need help w/ that), and it can do it for you automatically.

<?php
$file = "file.ext"; //the file name
$remote_url = "http://example.com/"; //the server address (minus the file name)
$local_dir = "c:/xampp/htdocs/your_folder"; //the directory you want the file saved to (absolute path)
/* STOP EDIT */
$full_file = $local_dir.$file;
$dl_file = file_get_contents($remote_url.$file);
print $dl_file;
$fh = fopen($full_file, "w+");
fwrite($fh, $dl_file);
fclose($fh);

?>

this should fix you up.

<?php
$file = "file.ext"; //the file name
$remote_url = "http://example.com/"; //the server address (minus the file name)
$local_dir = "c:/xampp/htdocs/your_folder"; //the directory you want the file saved to (absolute path)
/* STOP EDIT */
$full_file = $local_dir.$file;
$dl_file = file_get_contents($remote_url.$file);
print $dl_file;
$fh = fopen($full_file, "w+");
fwrite($fh, $dl_file);
fclose($fh);

?>

this should fix you up.

 

That my friend is awesome.  It works..  Now the question is, when i download a .rar file, when the download is over the screen in IE displays the contents of the file which is junk.  Can I prevent that from happening so tat the script can continue on to do other stuff?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.