Re: File Upload using ftp commands
From: David (twofish_at_sbcglobal.net)
Date: 03/09/04
- Next message: Eric Bohlman: "Re: alternating row colors on query generated table?"
- Previous message: LRW: "Re: alternating row colors on query generated table?"
- In reply to: David: "File Upload using ftp commands"
- Next in thread: Shawn Wilson: "Re: File Upload using ftp commands"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 09 Mar 2004 01:39:00 GMT
Dude:
Here I am replying to myself on the list so that others won't suffer as
I have. I finally figured out that ftp_put and ftp_fput are running *on
the server* and so don't know anything about the client's file system.
They are putting files from the php server onto some other remote
server. Therefore, the only file they are going to know about is the
temp file that php creates on the fly. Once I changed my code to use the
php tmp file, the upload worked smoothly.
HTH,
David
David wrote:
> 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
>
> [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);
>
> ?>
> [/code]
- Next message: Eric Bohlman: "Re: alternating row colors on query generated table?"
- Previous message: LRW: "Re: alternating row colors on query generated table?"
- In reply to: David: "File Upload using ftp commands"
- Next in thread: Shawn Wilson: "Re: File Upload using ftp commands"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|