开发者

How the ftp uploads works in PHP?

开发者 https://www.devze.com 2023-03-16 13:03 出处:网络
I am using thehttp://phpseclib.sourceforge.net/ library for file uploading usin开发者_运维知识库g ftp.Now I cant able to understand the concept behind this \"how the ftp handling the file data while u

I am using the http://phpseclib.sourceforge.net/ library for file uploading usin开发者_运维知识库g ftp.Now I cant able to understand the concept behind this "how the ftp handling the file data while uploading".

what happend is:

I created the form for file upload with submit button.When I choose the file and click on submit the loader starts.But the file not coming into server.My expectation is when I click the submit button it reads the data from the file and push into the server depending upon the packet size mentioned in phpseclib.

Any one explained me what I misunderstood or whats happening while the loader showing in the browser?

EDIT:

File upload has no issues.Only thing is why its called so late.So while uploading whether the php move the file to server into some tempdirectories. If so why I need to go for ftp upload.

I tested with 100Mb files.Files are uploaded.What my expectation is why it doesnt start immediately after click submit button?


Do you have enctype="multipart/form-data" for your form?

In html, forms need the enctype="multipart/form-data" attribute to upload a file. The form usually looks like this:

<form id="form_id" enctype="multipart/form-data" method="POST">
<input type="file" name="file" />
<input type="submit" name="submit" value="submit" />
</form>


I'm confused. Can you post the relevant PHP code that shows

  1. your handling of the POST request that uploads the file
  2. how you call the FTP library to initiate the FTP transfer

What I think is happening is this: your user uploads a file to your webserver, then you initiate FTP from your webserver to the FTP server. There are 2 uploads here; 1 via HTTP and 1 via FTP. You won't see the FTP upload commence until the HTTP upload is complete.


Great question, you are dealing with 2 transaction here. The first transaction puts the file into a location on your web server. This uses HTTP as a transport via a POST method (also likely the slowest part of this transaction).

Once the initial client side upload is complete the file will be stored on your web server where a S/FTP script can now transfer.

Reading the comment below what you wanted was to transfer the file using FTP from the client side, and that's a perfectly viable solution. However this is the current process you implemented.

Your process currently.

  1. User A uploads a file via HTTP using a web page you host.
  2. User A waits until file upload has completed before closing his browser.
  3. File is saved in the directory path specified in the upload script.
  4. S/FTP script reads the file and initiates a connection with a foreign S/FTP server and begins transferring the file to that server.

If step 4 is redundant then the S/FTP script is not required at all unless what you wanted was to transfer via S/FTP from the client.

Your intention.

  1. User A uploads a file via S/FTP using a browser based S/FTP client.
  2. User A waits for file upload to complete.
  3. File is saved in the directory path specified in the upload script.

In the comments you mentioned possibly implementing a Flex solution. Here are some resources I found that might help.

Flex FTP based client

Flex based FTP Client question on Stack Exchange

Implement a S/FTP client on the server side with PHPSecLib.

SFTP.php on Gist (for line numbers and highlighting)

Original PHPSec SFTP.php

I copied the original via the Sourceforge site to Gist so you can use the line numbers as a guide. The SFTP library expects either a full path to file (i.e /tmp/somefilehere ) or a valid PHP file resource. Like the one returned by fopen $fp = @fopen('/tmp/somefilehere', 'rb'); see line 1132 on gist for an example.

Once authenticated the transfer will be pretty quick compared to the initial upload. Your Server is likely in a data centre with much more bandwidth so file transfers are much faster.

You probably want to initiate a S/FTP transaction via your web browser. Its possible just not with conventional scripting languages like PHP / Python or Ruby. You can S/FTP from the browser with Flash, Flex or Java and probably some Windows technologies too.

0

精彩评论

暂无评论...
验证码 换一张
取 消