Professional Web Applications Themes

uploading files to remote ftp servers - PHP Development

Hi, How can I allow a user to upload a file to a remote ftp site? I know how to make the file be uploaded to the same server as the php script that I want to use, but not to a remote server. Im doing this using the following code: $uploaddir = realpath("upload/")."/"; $uploadfile = $uploaddir . $_FILES['userfile']['name']; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { // successful upload } I found this example on the net: $file = fopen ("ftp://ftp.example.com/incoming/outputfile", "w"); if (!$file) { echo "<p>Unable to open remote file for writing.\n"; exit; } /* Write the data here. */ fputs ($file, ...

  1. #1

    Default uploading files to remote ftp servers

    Hi,

    How can I allow a user to upload a file to a remote ftp site?

    I know how to make the file be uploaded to the same server as the php
    script that I want to use, but not to a remote server. Im doing this
    using the following code:

    $uploaddir = realpath("upload/")."/";
    $uploadfile = $uploaddir . $_FILES['userfile']['name'];
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    // successful upload
    }


    I found this example on the net:

    $file = fopen ("ftp://ftp.example.com/incoming/outputfile", "w");
    if (!$file) {
    echo "<p>Unable to open remote file for writing.\n";
    exit;
    }
    /* Write the data here. */
    fputs ($file, $_SERVER['HTTP_USER_AGENT'] . "\n");
    fclose ($file);


    but how do I modify this to "put" a file from the users HD onto the
    remote ftp site?


    Thanks!

    Andrew
    Andrew Guest

  2. #2

    Default Re: uploading files to remote ftp servers

    "Andrew Bullock" <com> kirjoitti
    viestissä:_Oloe.438$ntli.net... 


    You let the user upload the file first to your server and store it to a
    temp, then you open the ftp uploader and send it there yourself, with the
    script you have. Use a multipart form that has a file field as an interface
    for the user. See handling file uploads from the manual for details.



    --
    "I am pro death penalty. That way people learn
    their lesson for the next time." -- Britney Spears

    com


    Kimmo Guest

  3. #3

    Default Re: uploading files to remote ftp servers

    Kimmo Laine wrote: 
    >
    >
    >
    > You let the user upload the file first to your server and store it to a
    > temp, then you open the ftp uploader and send it there yourself, with the
    > script you have. Use a multipart form that has a file field as an interface
    > for the user. See handling file uploads from the manual for details.
    >
    >
    >[/ref]


    Do i need to remove the temp file after uploading or will a gc get it?
    Don't want to clog the servers tmp directory


    Thanks

    Andrew
    Andrew Guest

  4. #4

    Default Re: uploading files to remote ftp servers

    "Andrew Bullock" <com> kirjoitti
    viestissä:H9noe.7105$ntli.net... 
    >>
    >>
    >>
    >> You let the user upload the file first to your server and store it to a
    >> temp, then you open the ftp uploader and send it there yourself, with the
    >> script you have. Use a multipart form that has a file field as an
    >> interface for the user. See handling file uploads from the manual for
    >> details.
    >>
    >>
    >>[/ref]
    >
    >
    > Do i need to remove the temp file after uploading or will a gc get it?
    > Don't want to clog the servers tmp directory
    >
    >[/ref]

    "The file will be deleted from the temporary directory at the end of the
    request if it has not been moved away or renamed. "
    - PHP Manual, Handling File Uploads

    Told you to read the manual, didn't I?

    --
    "I am pro death penalty. That way people learn
    their lesson for the next time." -- Britney Spears

    com


    Kimmo Guest

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139