Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Upload Pictures to Website?

    Hello all...

    I'm trying to code some PHP to upload a selected file from the user's PC to an FTP site.

    Basically what I understand is this:

    1. The User Needs to Select The File
    2. The file then needs to be uploaded to the php server. (I.e. my computer running apache/php 5)
    3. The PHP then needs to use that local file and upload it to the selected FTP site.
    4. The FTP site connection needs to close
    5. The local file on the web server (i.e. my computer running apache/php 5) needs to be deleted.
    6. The user then needs to be aware of the success or failure of the upload.



    Ok, so for #1 I've used a page called "ftp.php" that shows a very simple forum input. This then POSTs over to the upload.php file.

    PHP Code:
    <body>

    <
    form action="upload.php" method="post"
    enctype="multipart/form-data">
    <
    label for="file">Filename:</label>
    <
    input type="file" name="file" id="file" /> 
    <
    br />
    <
    input type="submit" name="submit" value="Submit" />
    </
    form>

    </
    body
    The problem is... when it uploads to my Apache server, the file that was selected is 100% fine. However, if I try to copy it over to the FTP site, the file size is "0". It is an empty file!

    I've tried a very simple bit of code:

    PHP Code:
    <?php

    $conn 
    ftp_connect("ftp.site.here") or die("Could not connect"); // site address
    ftp_login($conn,"username","password") or die("Could not login"); // login information

    echo ftp_put($conn,"target.txt","source.txt",FTP_ASCII) or die("Could not Upload");  
                                                            

    ftp_close($conn);                                  // closes the connection 


    ?>

    Now, if I put some jibberish in the source.txt file... like "lkasdjflkjaslkj", it will upload to the FTP site and be its great self at like 20 bites of information. HOWEVER, if I try to use a .jpg image, that is say ~200K in size, the resultant file is a 0 bite empty shell.


    So how I tested this was, I found a random file in my documents, sample images folder and threw it right next to the .php file I am using (same that I did with the source.txt file) that way I could eliminate file paths and just mess with the file name.

    PHP Code:
    echo ftp_put($conn,"Creek.jpg","Creek.jpg",FTP_ASCII) or die("Could not Upload"); 
    This makes a copy of "Creek.jpg" on my FTP site, but it is empty! 0 bites of data.

    I also tried
    PHP Code:
    echo ftp_put($conn,"Creek.jpg","Creek.jpg",FTP_[B]BINARY[/B]) or die("Could not Upload"); 
    and that did not work either, still an empty file.

    Maybe it is
    PHP Code:
    ftp_close($conn);                                  // closes the connection 
    using that code too quickly before the file even gets to upload properly? I'm not entirely too sure how it works...

  • #2
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I do believe it was the fact the FTP site I was using was OUT OF FREAKIN' SPACE...

    So I do believe it works now, I'll let you guys know if it doesn't.

    Although, is there any way to upload directly to the FTP site from the user's PC?

    Instead of from Their PCto the Apache/PHP5 serverto the FTP Site.
    I'd like: Their PC to the FTP Site is that possible?


  •  

    Posting Permissions

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