PHP 中的 ftp 上传是如何工作的?
我正在使用 http://phpseclib.sourceforge.net/ 库使用 ftp 上传文件。现在我不能能够理解“ftp 在上传时如何处理文件数据”背后的概念。
发生的情况是:
我使用提交按钮创建了用于文件上传的表单。当我选择文件并单击提交时,加载程序启动。但是文件没有进入服务器。我的期望是当我单击提交按钮时,它会从中读取数据文件并根据 phpseclib 中提到的数据包大小推送到服务器中。
任何人都可以解释一下我误解了什么或者加载程序在浏览器中显示时发生了什么?
编辑:
文件上传没有问题。唯一的问题是为什么调用这么晚。因此,在上传时,php 是否将文件移动到服务器的某些临时目录中。如果是这样,为什么我需要进行 ftp 上传。
我用 100Mb 文件进行了测试。文件已上传。我的期望是为什么它在单击提交按钮后没有立即启动?
I am using the http://phpseclib.sourceforge.net/ library for file uploading using 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的表单有
enctype="multipart/form-data"
吗?在 html 中,表单需要
enctype="multipart/form-data"
属性来上传文件。表格通常如下所示:
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:
我很困惑。您能否发布相关的 PHP 代码来显示
我认为发生的情况是这样的:您的用户将文件上传到您的网络服务器,然后您启动从您的网络服务器到 FTP 服务器的 FTP。这里有2个上传; 1 个通过 HTTP,1 个通过 FTP。在 HTTP 上传完成之前,您不会看到 FTP 上传开始。
I'm confused. Can you post the relevant PHP code that shows
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.
好问题,您正在处理两笔交易。第一个事务将文件放入 Web 服务器上的某个位置。这使用 HTTP 作为通过 POST 方法的传输(也可能是此事务中最慢的部分)。
初始客户端上传完成后,文件将存储在您的 Web 服务器上,S/FTP 脚本现在可以在其中传输。
阅读下面的评论,您想要的是从客户端使用 FTP 传输文件,这是一个完全可行的解决方案。然而,这是您当前实施的流程。
您当前的进程。
如果步骤 4 是多余的,则根本不需要 S/FTP 脚本,除非您想要通过 S/FTP 从客户端传输。
您的意图。
在评论中您提到可能实施 Flex 解决方案。以下是我发现的一些可能有帮助的资源。
基于 Flex FTP 的客户端
Stack Exchange 上基于 Flex 的 FTP 客户端问题
实施 S/FTP服务器上的客户端与 PHPSecLib 站在一起。
Gist 上的 SFTP.php(用于行号和突出显示)
原始 PHPSec SFTP.php
我通过 Sourceforge 站点将原始文件复制到 Gist,以便您可以使用行号作为指导。 SFTP 库需要文件的完整路径(即 /tmp/somefilehere )或有效的 PHP文件资源。就像 fopen 返回的那样
$fp = @fopen('/tmp/somefilehere', 'rb');
请参阅要点上的第 1132 行作为示例。经过身份验证后,与初始上传相比,传输速度会相当快。您的服务器可能位于带宽更多的数据中心,因此文件传输速度更快。
您可能想通过 Web 浏览器启动 S/FTP 事务。只是使用 PHP / Python 或 Ruby 等传统脚本语言是不可能的。您可以使用 Flash、Flex 或 Java 以及可能还有一些 Windows 技术从浏览器进行 S/FTP。
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.
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.
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.