Because of limitations of my provider, I am forced to use the ftp
functions to upload files to my server (the permissions on the server
will not allow me to load files via php).
I have successfully ported the sample code from php.net to do everything
BUT upload the file. I can connect. I can log in. I can change
directories. But the file never uploads. As I note in the code, I have
tried using ftp_put with the local filename, and I have tried using
ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.
David
functions to upload files to my server (the permissions on the server
will not allow me to load files via php).
I have successfully ported the sample code from php.net to do everything
BUT upload the file. I can connect. I can log in. I can change
directories. But the file never uploads. As I note in the code, I have
tried using ftp_put with the local filename, and I have tried using
ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.
David
Code:
---------------------
<?php
$tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
echo "<pre>" . print_r($tmp) . "</pre>";
$upload_form_file = $tmp['name']; // have tried using the tmp_name
element combined with ftp_fput
$dest_file = "bob.gif"; // just a name to try
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
$ftp_server"); // works
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
} else {
echo "Couldn't connect as $ftp_user\n";
}
echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
this gives the root
if (ftp_chdir($conn_id, $base_path)) {
echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
// this prints /the/path/to/docs
} else {
echo "Couldn't change directory\n";
}
echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
</p>\n"; // files are listed
if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
echo "successfully uploaded";
} else {
echo "There was a problem while uploading $file\n"; // this always
triggers
}
// close the connection
ftp_close($conn_id);
?>
Comment