SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question ftp_put() doesn't work here... what's wrong?

    My problem is that after the upload, my filesize is 0 bytes...
    the ftp_put() function is stated correctly, because it doesn't
    return an error and it says the file is uploaded, but when I
    check the file I see that he didn't upload a single bit, only
    made the file...
    Can anyone tell me what to do?
    There is no signature...

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought they were smart here... nobody knows an answer?!?
    There is no signature...

  3. #3
    SitePoint Addict
    Join Date
    May 2004
    Location
    USA
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They are, why don't you show some code.

    What you have given us is the equivelent to me saying, "my car doesn't work, there is no smoke. What's wrong?"

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the file ftp.inc.php:
    PHP Code:
    <?
    $ftp_server   
    gethostbyname('ftp.dmbproductions.nl');
    $conn_id      ftp_connect($ftp_server);
    $user         "******";
    $passwd       "******";
    $login_result ftp_login($conn_id$user$passwd);
    if ((!
    $conn_id) || (!$login_result)) {
       echo 
    "<br>Attempted to connect to $ftp_server for user $user<br>";
       echo 
    "FTP connection has failed!";
       die;
    }
    ftp_pasv($conn_idtrue);
    ?>
    index.php (only related part):
    PHP Code:
    require('ftp.inc.php');
    require(
    '../config.inc.php');
    $type      $_POST['type'];
    $dateadded date('Y-m-d');
    if (
    $type == 'Java') {
       
    /*
        * non related
        */
       
    ftp_chdir($conn_id,'public_html/Java/downloads');
    } elseif (
    $type == 'Pic') {
       
    /*
        * non related
        */
       
    ftp_chdir($conn_id,'public_html/Pics/downloads');
    } elseif (
    $type == 'Ring') {
       
    /*
        * non related
        */
       
    ftp_chdir($conn_id,'public_html/Ringtones/downloads');
    }
    $upload ftp_put($conn_id$file$sourceFTP_BINARY);
    if (!
    $upload) {
       
    $uresult  'failed';
       
    $m1result 'not done';
       
    $m2result 'not done';
    } else {
       
    $uresult 'uploaded';
       
    $query1  "INSERT INTO `fms_$what` ($tables) VALUES ($values)";
       if (!
    mysql_query($query1$serverid)) {
          
    $m1result 'failed';
          
    $m2result 'not done';
       } else {
          
    $m1result 'inserted';
          
    $query2   "INSERT INTO `fms_updates` (`update_type`,`update_date`) VALUES ('$what','$dateadded')";
          if (!
    mysql_query($query2$serverid)) {
             
    $m2result 'failed';
          } else {
             
    $m2result 'inserted';
          }
       }
    }
    ftp_close($conn_id); 
    results: uploaded; inserted; inserted.
    filesize remains 0 Bytes. (and the inserts are done).
    There is no signature...

  5. #5
    SitePoint Member
    Join Date
    Apr 2005
    Location
    Rochester, New York
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just had this problem. Do you ever define $source?

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually it looks as if neither $file OR $source are set.

    I'll also refer you to the article linked in my signature regarding short tags.

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $file & $source are defined in the form (not related part).
    and yes, the source in the form is a 'file' type.
    There is no signature...

  8. #8
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You shouldn't use register globals. You should use $_POST['file'] and $_POST['source'], not $file and $source.

    Also, what is $file defined to? Are you using an <input type="file" /> to do a post upload? Or is it the file name of a file already on the server?

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $source = $_POST['java_source_file'];
    Already present...

    <input type='file' name='java_source_file' size='20'>
    Also there...

    $file is just only the new name... (for on the server)
    There is no signature...

  10. #10
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right. Files aren't used in $_POST. You'll need to use $_FILES['java_source_file']['...'] in order to get to it. That's the issue. See: http://ca.php.net/manual/en/features.file-upload.php

  11. #11
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I might be stating the obvious here but you can't upload a file via ftp using an <input type="file". If that were possible i could write a script to pull any file off your local system.

  12. #12
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by markl999
    I might be stating the obvious here but you can't upload a file via ftp using an <input type="file". If that were possible i could write a script to pull any file off your local system.
    You can, but you need to do the standard upload files and then FTP it from the server to the second server. It's kind of... pointless... but it's possible.

  13. #13
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that's what i meant. The file needs to reside on the same server running the ftp_put() command. If it's a remote server that means uploading it first using the normal methods, if it's local then just use a text box to type the path/name in.

  14. #14
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed it to
    $source = $_FILES['java_source_file']['name'];

    now it says 'failed'...
    There is no signature...

  15. #15
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you're going to need to explain which failed that is. There's more than one in your code.

  16. #16
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $uresult = failed.
    But I found the solution:
    $source = $_FILES['java_source_file']['tmp_name'];

    when you submit the form, the file in the form is uploaded automatically to the temp-dir at the server.
    all you have to do with ftp_put() is put it in the right place

    Thnx for the helping someonewhois!
    There is no signature...

  17. #17
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by markl999
    I might be stating the obvious here but you can't upload a file via ftp using an <input type="file". If that were possible i could write a script to pull any file off your local system.
    muhahaha, wrong, I just did it...
    There is no signature...

  18. #18
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well what i said is correct, i just didn't realise you were doing a normal upload first then using ftp_put as i and someonewhois stated previously
    Anyway, glad you got it working.

  19. #19
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, you're using tmp_name. If you echo that out, go into shell, and go to the file, you'll notice that that file is sitting on your server even before you ftp it. You're using a POST upload and then FTP'ing it from your server to the other server, for whatever reason.

    Mark was correct.

  20. #20
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me explain what is done:
    in the form i select a file on my computer in the file-box.
    when I submit the form, the file in the form will be copied to the tmp-directory of the server.
    then I use ftp_put() to put in in the right place at the same server.

    So what you guys are talking about 'from one server to another for whatever reason' is totally nonsense.

    but no more replies, I finished it, it works great, no more problems, this thread is over.
    There is no signature...

  21. #21
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's inefficient and slow. You can use move_uploaded_file for the exact same task that you're trying to accomplish, except you don't need to FTP to yourself. It's a bit silly to FTP into localhost when you're already on the server, and it'll be slower than just moving the file.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •