473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Jul 17 '05 #1
2 2253
*** 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
--
Jul 17 '05 #2
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

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tihon | last post by:
Hello! I again need your help, just can't understand whats going on. Got this upload pictures form and it's having problem handling large files (~1.5 - 2 MB). Everything works fine if i just...
2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
2
by: Erik R.N. | last post by:
Hi 2 years ago i managed to set up my PC to be able to upload semicolonseparated database-files to my mysql-database on a webhost-server which also contain my website (from where one can do search...
8
by: Murali Inguva | last post by:
I am getting the following error. I Created a Web Project then added upload.aspx Then I got this error. I keep aspx controls i am geeting this error. I have xp pro with IIS Installed then i...
3
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
2
by: Yandos | last post by:
Hi php gurus, I need to create an array which will contain more keys with same name, but of different values. I have no idea how to do it. Could you please help me? This is what I'd like to...
3
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it...
0
by: aris1234 | last post by:
hello.. How to upload image file in page update ..?? i have logic like this : if user upload new image then old image must delete and update DB used new name if user not upload new image then...
0
by: eliana | last post by:
Hello I'm trying to write some code to upload video to YahooVideo! I'm using cUrl.. Basically I go trough the following steps: 1 call the login page 2 get challenge and user values 3 send...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.