View Full Version : PHP ftp functions
mickdanger
Jul 20, 2005, 04:26 AM
I am trying to write a page to ftp files from my PC to my website. I am able to connect and log in using ftp_connect() and ftp_login(), but the ftp_put function won't work. What do I use as the values for the parameters?
$upload= ftp_put($conn_id,$destination_file,$source_file,FT P_ASCII);
if (!$upload)
{echo"sorry, didn't work.";}
else
{echo"OK!";}
ftp_close($conn_id);
?>
LTheobald
Jul 20, 2005, 04:56 AM
Whenever you get stuck on a PHP problem, check the PHP manual first. It's fantastic for things like this - PHP Manual: ftp_put() (http://uk.php.net/manual/en/function.ftp-put.php). There is also a full example for you to take a look at.
The parameters needed are in your example are:
$conn_id
This is the FTP connection you established using ftp_connect() (http://uk.php.net/manual/en/function.ftp-connect.php)
$destination_file
The file path of what you want to send. E.g. 'C:\test.txt'
$source_file
Where you want this file stored on your FTP server. E.g. '\public_html\test.txt'
FTP_ASCII
This is a constant defining the transfer mode. It must either be FTP_ASCII (used for text (ASCII) based files) or FTP_BINARY for binary files (executables, sound files etc.) Note: There was a space in the FTP_ASCII constant in your example - remove that or the function won't work.
For a full list of PHP's FTP functions, check here (http://uk.php.net/ftp)
One final tip: When posting PHP code into the forum, surround it by the [ code ][/ code ] brackets (remove spaces). It makes it look better:
<?php
function sayHello() {
// Code is formatted nicely
echo 'Hello world!';
}
?>