This is a discussion on Help with ftp upload please within the PHP Language forums, part of the PHP Programming Forums category; Hi I am using a form to upload an image from my hard drive to my server but there is ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi
I am using a form to upload an image from my hard drive to my server but there is something amiss cause I am continually getting an error message "FTP upload has failed" This is my code <?php if (!isset($_POST['upload'])) { ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p align="left"><font size="2">Type the file to upload here </p> <input type="text" name="filename" size="25"> <input type="submit" value="Upload" name="upload" style="color: #000000; font-family: Arial; background-color: #D56A00; border-style: solid; border-color: #FF0066"></p> </form> <?php } else { $source = "D:\\My Documents\\My Pictures\\" . $_POST['filename']; $destination = "/images/".$_POST['filename']; $ftp_server = "myftpserver"; $ftp_user_name = "myusername"; $ftp_user_pass = "mypassword"; $conn_id = ftp_connect($ftp_server) or die ("Could not connect to $ftp_server"); $login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass); if((!$conn_id)||(!$login_result)) { echo "FTP connection has failed"; exit; } else { echo "Connected to FTP server"; $upload = ftp_put($conn_id,$destination,$source,FTP_BINARY); if (!$upload) { echo "FTP upload has failed"; } else { echo "Successfully uploaded file"; } } } ?> </body> </html> Any help greatly appreciated as always |
|
|||
|
*** Dynamo wrote/escribió (13 Jan 2005 05:23:12 -0800):
> I am using a form to upload an image from my hard drive to my server but there > is something amiss cause I am continually getting an error message "FTP upload > has failed" I've seen many people trying to read a local file from a script running in a remote server. Please note that this code... > $source = "D:\\My Documents\\My Pictures\\" . $_POST['filename']; ....implies that the web server is running in your PC. Is it the case? -- -- Álvaro G. Vicario - Burgos, Spain -- Thank you for not e-mailing me your questions -- |
|
|||
|
Hi,
You don't have to use the PHP ftp_* commands to upload an image from your local PC to the server. All you need is your PHP script to receive the posted file contents (along with original filename and MIME Type) and then handle it suitably (either save to database or write to filesystem). Please refer http://us3.php.net/manual/en/features.file-upload.php for a good description on how this is achieved using PHP. So your code should be (untested, heck not even executed once!): Remove leading //-. Included so that GG does not screw up indentation //-<?php //-if (empty($myfile)) { //-?> //- <form method="post" action="insert.php" enctype="multipart/form-data"> //- File: <input name="myfile" type="file"><br /> //- <input type="submit" value="Submit"><br /> //- <input type="hidden" name="MAX_FILE_SIZE" value="30000"> //- </form> //-<?php //-} else { //- $Home = '/home/unixuser/public_html/images' ; //- if (is_uploaded_file($myfile)) { //- $move_status = @move_uploaded_file($myfile, "$Home/$myfile_name"); //- if ($move_status) { //-?> //- <h5>File Uploaded successfully</h5> //-<?php //- } else { //-?> //- <h5 style="color:red">File upload failed</h5> //-<?php //- } //-?> And dont forget about the addslashes() function. You image might be already escaped if your magic_quotes_gpc option is set in php.ini. Thanks, --Kartic |