Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ftp_put works with Text based files but not Images

Posted on 2007-04-03
3
Medium Priority
?
276 Views
Last Modified: 2009-12-16
I'm using ftp_put to upload files.  It works with text based files but not on images. I've tried with small file sized images and used FTP_BINARY. The images are well under the upload liimit and ftp iIS enabled with PHP.

I'm using the following script to FTP files to server.

<?php
if($submit){

// set up basic connection
$ftp_server = "www.skunk2.com";
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = "****";
$ftp_user_pass = "******";
//capture file source from form
$source_file = $file;
$destination_file = "test.jpg";
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

ftp_chdir($conn_id, "websites");
ftp_chdir($conn_id, "www.skunk2.com");
ftp_chdir($conn_id, "html");

// check connection
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. ";
    }

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// check upload status
if (!$upload) {
        echo "FTP upload has failed!";
    } else {
        echo "Uploaded $source_file to $ftp_server as $destination_file";
    }

// close the FTP stream
ftp_close($conn_id);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

      <head>
            <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
            <meta name="generator" content="Adobe GoLive">
            <title>Untitled Page</title>
      </head>

      <body bgcolor="#ffffff">
            <form id="FormName" action="ftpTest.php" method="get" name="FormName">
                  <input type="file" name="file" size="41"><br>
                  <br>
                  <input type="submit" name="submit" value="submit">
            </form>
            <p></p>
      </body>

</html>
0
Comment
Question by:boynatural
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Jeff Darling earned 500 total points
ID: 18850898

I don't see how this code works at all.

First, the form isn't setup correctly.  It shold be a POST not a GET.  Also try adding enctype to the form.

like this:

<form id="FormName" action="ftpTest.php" method="POST" name="FormName" enctype="multipart/form-data">


Second, you probably don't need the ftp_chdir lines.  Try removing them and see if your file gets uploaded to the default directory for the ftp user account that you are using. (change the form as specified above)

You probably want to name the file on your server the same as it was on the submitted from the form.

$destination_file = $_FILES['file']['name'];



0
 

Author Comment

by:boynatural
ID: 18853327
I was using the form to pass the location. By adding your adjustment it worked with images. Does the form actually pass the file or just a reference to location??
0
 
LVL 13

Expert Comment

by:Jeff Darling
ID: 18854122

The form passes the filename parameter needed by the PHP process.  The PHP code is actually skipped based on the results of this test:  

if($submit)

If the form isn't submitted, then it just displays the form.

I'm not sure why it worked for you on text files.  I have no explanation on that.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question