Help with ftp upload please

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-13-2005
Dynamo
 
Posts: n/a
Default Help with ftp upload please

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 &nbsp;</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

Reply With Quote
  #2 (permalink)  
Old 01-13-2005
Alvaro G Vicario
 
Posts: n/a
Default Re: Help with ftp upload please

*** 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
--
Reply With Quote
  #3 (permalink)  
Old 01-13-2005
Kartic
 
Posts: n/a
Default Re: Help with ftp upload please

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:28 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0