02.05.2012, 02:44
Hey. I have a php script for players to download their 'maps' from my server, via FTP. I've got the ftp connecting and logging in, but I'm unsure about having them download the files. I've been googling and stuff and read about ftp_get, but it says it downloads as a local file.
Does this mean I download it as a local file, then re-direct them to that url, then delete the file? If so could I get some guidance? Thanks.
P.S. New to php.
EDIT: Eh, just making it up as I go along, added the ftp_get shit but getting this:
This is the relevant php code:
Does this mean I download it as a local file, then re-direct them to that url, then delete the file? If so could I get some guidance? Thanks.
P.S. New to php.
EDIT: Eh, just making it up as I go along, added the ftp_get shit but getting this:
Quote:
Connected as xxx@x.x.x.x Warning: ftp_get() [function.ftp-get]: The system cannot find the file specified. in /xxx/mapload.php on line 62 There was a problem downloading the file. /scriptfiles/maps/James_1.txt |
PHP код:
$resultPath = "/scriptfiles/maps/" . $_POST['pname'] . "_" . $_POST['slot'] . ".txt";
$ftp_server = "...";
$ftp_user = "...";
$ftp_pass = "...";
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) echo "Connected as $ftp_user@$ftp_server\n";
else echo "Couldn't connect as $ftp_user\n";
$local_file = 'map.txt';
$server_file = '$resultPath'; // Also tried without apostrophes (')
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) echo "Successfully written to $local_file\n";
else echo "There was a problem downloading the file.\n";
// close the connection
ftp_close($conn_id);