Forum Moderators: coopster
However, I want to ftp_put() files to my server and I'm not entirely sure how else to allow my user to find the files.
Any workarounds? Or am I likely just doing it wrong? How do you all make the ftp_put() know what file you want to upload from your hard disk?
BTW, I am successfully connecting, and a file does, in fact, show up where I want it to on my server with the name I give it, but it's not the one I tell it to upload in my <input type="file"...> tag.
Tom
<body>
<form action="ftp.php" method="post" name="ftp_form" enctype="multipart/form-data">
<p>Host Name:<br/>
<input name="ftp_server" type="text" value="www.servername.com">
</p>
<p> User Name:<br/>
<input name="user_name" type="text">
</p>
<p> Password:<br/>
<input name="user_pass" type="text">
</p>
<p><input name="file_name" type="file"></p>
<input name="submit" type="submit" value="upload">
</form>
</body>
</html>
-------------------------------------
and the php that should upload it:
-------------------------------------
<?php
$ftp_server=$_POST['ftp_server'];
$conn_id = ftp_connect($ftp_server);
$ftp_user_name=$_POST['user_name'];
$ftp_user_pass=$_POST['user_pass'];
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ((!$conn_id) ¦¦ (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
ftp_chdir($conn_id, "htdocs");
ftp_chdir($conn_id, "hostPics");
$destination_file = "x.txt";
$source_file = $_POST['file_name'];
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $_POST['file_name']";
}
ftp_close($conn_id);
?>
---------------------------------
Again, it does upload a file called x.txt into the directory called hostPics on the server, but x.txt isn't the same as the file I selected from my hard disk.
I know, most of you have probably seen this code before and I am aware of the danger of cutting and pasting found-on-the-internet code, but it all looks good and mostly works.
Any ideas?
Thanks in advance,
Tom
I want my customer to be able to upload pictures from his own computer to a remote server. This server hosts his site. But I want him to be able to open a password protected page on his site from any computer, and upload files from that computer to his site.
So, to modify your example, I want him to upload from Client A to Web-Server B.
But I'm wondering if that's even possible. I've downloaded a few php apps, like online photo albums, and they don't allow for uploading... they thumbnail and manipulate, but they normally say to upload files "with your favourite ftp program"
Maybe I should say the same thing.
?
Tom