Help with ftp upload please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dynamo

    #1

    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"><f ont 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 = "myftpserve r";
    $ftp_user_name = "myusername ";
    $ftp_user_pass = "mypassword ";
    $conn_id = ftp_connect($ft p_server) or die ("Could not connect to $ftp_server");
    $login_result = ftp_login($conn _id,$ftp_user_n ame,$ftp_user_p ass);
    if((!$conn_id)| |(!$login_resul t)) {
    echo "FTP connection has failed";
    exit;
    }
    else {
    echo "Connected to FTP server";
    $upload = ftp_put($conn_i d,$destination, $source,FTP_BIN ARY);
    if (!$upload) {
    echo "FTP upload has failed";
    }
    else {
    echo "Successful ly uploaded file";
    }
    }
    }
    ?>
    </body>
    </html>

    Any help greatly appreciated as always

  • Alvaro G Vicario

    #2
    Re: Help with ftp upload please

    *** Dynamo wrote/escribió (13 Jan 2005 05:23:12 -0800):[color=blue]
    > 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"[/color]

    I've seen many people trying to read a local file from a script running in
    a remote server. Please note that this code...
    [color=blue]
    > $source = "D:\\My Documents\\My Pictures\\" . $_POST['filename'];[/color]

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

    Comment

    • Kartic

      #3
      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="multip art/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_fi le($myfile)) {
      //- $move_status = @move_uploaded_ file($myfile,
      "$Home/$myfile_name");
      //- if ($move_status) {
      //-?>
      //- <h5>File Uploaded successfully</h5>
      //-<?php
      //- } else {
      //-?>
      //- <h5 style="color:re d">File upload failed</h5>
      //-<?php
      //- }
      //-?>

      And dont forget about the addslashes() function. You image might be
      already escaped if your magic_quotes_gp c option is set in php.ini.
      Thanks,
      --Kartic

      Comment

      Working...