Hi Everyone,

On my website I upload files from local computer to my server using FTP functions in PHP. It all works perfectly when I run the script from my pc, but once it s on the server it can t find the file.
ftp_put(): error opening C:\Documents and Settings\Alexander\Desktop\tr1_1.jpg

I guess it happens cos it tries to find it on the server not on my PC.
The question is, how can I point it to my pc, not server.
Or how can I make it copy files from my local computer to the server while running from the server!

Please any help is appreciated as I m running out of time!

Thank you guys!

Regards, Alex

    You can upload it from your PC to the server, but you can't ask the server to 'show me a file on my PC'. PHP runs on the server and has no access to what's on your PC.

    Check out the examples in the manual for ftp_put(), or better yet check out the handling file uploads section.

      In the form page the user chooses files to be uploaded to the server. While he s choosing them they will be added to the form as hidden fields one by one. Once the selection is finished and the user submits the form, the php file should upload all the files to the server. I can t do it using $_FILES with HTML uploader, so the ftp functions would be ideal.
      It is possible to achieve with HTML only if the form displays as many <input type="file"> fields as there are files to be downloaded. But what I have is only one of these fileds, there is also a button below it that when clicked would take the path from the file field and add it to the hidden field of the form!

      You can see it here

      http://www.truck-masters.co.uk/index.php?opt=new_product

      Please, advice what would be the best way to do this!

      Thanks in advance,

      Regards, Alexander

        your page seems to allow only one file, no? why cannot you use $_FILES? why do you have to use ftp?

          Instead of asking the guy why why why think maybe it's because to do ftp you need to know the username and pasword it's added security without the resource drain to upload to ftp in php use this code

          <HTML>

          <HEAD>

          <TITLE> Example Upload Form upload.phtml </TITLE>

          </HEAD>

          <BODY>

          <?php

          if ( $userfile ) {
          $conn_id = ftp_connect("ftp://localhost/");
          $login_result = ftp_login(, "username", "password");
          if (ftp_fput($conn_id, $userfile, $userfile_name, FTP_ASCII)) {
          echo "Successfully uploaded $userfile\n";
          }
          else {
          echo "There was a problem while uploading $userfile\n";
          }
          }
          ?>

          <FORM method=POST ENCTYPE="multipart/form-data">

          File to Upload

          <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="5000000">

          <INPUT NAME="userfile" TYPE="file" size=35>

          <INPUT TYPE="submit">

          </FORM>

          </BODY>

          </HTML>

          I'm pretty sure this should work for all files FTP_ASCII must be changed to FTP_BINARY any problems just shout loudly

            cyberlew15 wrote:

            Instead of asking the guy why why why think maybe it's because to do ftp you need to know the username and pasword it's added security without the resource drain to upload to ftp in php use this code

            oh, thanks. at least someone can think and correctly guess what the original post was about. I would also appreciate your explaining how the code you posted will help to transmit the files from the client through FTP, or HTTP or whatever.

              basically the first two if's are supposed to check if the form has submitted it's content (the file) if this has not happened the form is printed it is pretty self explanatory.

              If the form has been submitted it takes the file and put's it into a file on the ftp server

              if it cannot put the file on the ftp server it creates an error message Hope it worked coz it was'nt tested just jumbled 2gether

                well, it seems to me the code is invoked when an HTTP form is submitted to the server. what does this form contain? file contents? or the file path? ftp_fput() needs the handle of the open local file to upload it to the FTP server. where in your code is this local file opened? how does the HTTP server that runs this PHP code get this file? i am confused...

                  the http form is given the file data by your selection. when you click submit or upload then internet explorer sends the file to the server formatted as form data did the code work or not

                    Write a Reply...