SWFUpload - 有人熟悉吗?
我正在尝试 SWFUpload ( http://swfupload.org ),我想知道在 PHP 中,它是否数据仍将位于 $_FILES 数组中。 如果没有,它会去哪里?
I'm experimenting with SWFUpload ( http://swfupload.org ) and I'm wondering if, in PHP, its data will still be in the $_FILES array. If not, where does it go?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SWFUploader 使用 HTTP POST 上传文件。 因此,从 PHP 的角度来看,它与通过文件发布没有什么不同。
该文件将位于 $_FILES 中,额外的 postvars 将位于 $_POST 中。
SWFUploader uses HTTP POST to upload the files. So from PHP's perspective, it is not different than a being posted with a file.
The file will be in $_FILES and the extra postvars will be in $_POST.
我将发布一个使用 swfupload 和 PHP 的完整示例。 我相信 swfupload 文档对初学者来说不是很有帮助,这个例子会对很多人有所帮助。 您需要下载的是以下
内容首先复制/创建所有必需的文件
创建一个名为swfupload的文件夹并将以下文件从2.2.xy核心复制到其中
将以下文件从 2.2.x demos 文件夹复制到我们的 swfupload 文件夹
现在创建一个 PHP 脚本来接收 swfupload 文件夹内的文件(称为receiver.php)。 现在,您的文档根目录中有一个名为 swfupload 的文件夹,其中包含所有必需的文件。
使用 swfupload 控件创建测试 html 页面,
包括与 swfupload 控件交互的 javascript,
现在您必须在我们的测试 html 中包含 swfupload css 文件和所需的 javascript 文件。 我们还必须初始化并配置与 swfupload 控件交互所需的 js。
请查看您需要在设置中进行的更改。 现在我们准备好运行 PHP 脚本了。 我们将点击 PHP 脚本,PHP 脚本将返回一些我们的测试 html 可以使用的响应(例如文档位置,或者 doc_id,如果您存储在数据库中,则可以返回名称、大小、mime)等。
用于服务器端处理的 PHP 脚本
如果您知道如何在 PHP 中处理文件,那么您唯一需要知道的是 swfupload 发送的文件元素名称是 Filedata。 剩下的都是细节。 通过 $_FILES 处理文件上传后,您的接收器脚本可以返回一些数据,这些数据可用于更新带有文档详细信息的 html。 swfupload 论坛中包含的 PHP 上传示例纯粹是意大利面条。 如果您想查看面向对象的模型,请查看以下文件
http://code.google.com/p/localo/source/browse/job/web/swfupload/receiver.php
http://code.google.com/p/localo/source/browse/lib/webgloo/common/Upload.php
http://code.google.com/p /localo/source/browse/lib/webgloo/job/FileUpload.php
这仅用于说明目的。 该代码将无法正常工作,因为它依赖于我的库。
连接 PHP 脚本将数据返回到包含 swfupload 控件的 html 中
这是最后一步。 服务器脚本在成功上传时返回的内容应由 swfupload javascript 处理程序之一处理以更新 html(例如将返回的文件上传 URI 存储在文档中以进一步将其提交给其他脚本等)。您可以进行连线的方式是开放的/swfupload/js/handlers.js 并在那里进行更改。
您可以在此处热连您自己的 javascript。 有关示例(我正在更新文档表并将返回的文档元数据存储为表单文档中的 json 字符串),请参阅此处:
http://code.google.com/p/localo/source/browse/job/web/js/main.js
我希望这些信息足以帮助您开始使用 swfupload。 快乐编码:)
I am going to post a complete example using swfupload and PHP. I believe swfupload documents are not very helpful for beginners and this example would help many people. what you need to download is following
Copy/create all necessary files first
create a folder called swfupload and copy following files from 2.2.x.y core into it
copy following files from 2.2.x demos folder into our swfupload folder
Now create a PHP script to receive the file (call it receiver.php) inside swfupload folder. Now you have a folder called swfupload inside your document root that contains all the required files.
Create test html page with swfupload control
include javascript to interact with swfupload control
now you have to include swfupload css file and required javascript files inside our test html. we also have to initialize and configure the js required to interact with swfupload control.
Please see the changes that you need to do in settings. Now we are set to hit the PHP script. we will hit the PHP script and PHP script will return some response that our test html can use (things like doc location, or doc_id if you are storing in a DB, name,size,mime) etc. can be returned.
PHP script for server side processing
if you know how to handle files in PHP then the only thing you need to know is that the file element name sent by swfupload is Filedata. rest all is details. After processing your file upload via $_FILES , your receiver script can return some data that can be used to update your html with document details. The PHP upload sample included in swfupload forum is pure spaghetti. if you want to look @ an object oriented model, look @ following files
http://code.google.com/p/localo/source/browse/job/web/swfupload/receiver.php
http://code.google.com/p/localo/source/browse/lib/webgloo/common/Upload.php
http://code.google.com/p/localo/source/browse/lib/webgloo/job/FileUpload.php
That is for illustrative purpose only. The code will not work as it is as it has dependencies on my library.
wiring PHP script return data back into html containing swfupload control
This is the last step. what the server script returns on a successful upload should be processed by one of swfupload javascript handlers to update the html (say storing returned file upload URI in document to further submit it to some other script etc.) The way you can do wiring is open up /swfupload/js/handlers.js and make changes there.
You can hot wire your own javascript here. For a sample (I am updating a table of documents and storing returned documents meta data as a json string in form document) please see here:
http://code.google.com/p/localo/source/browse/job/web/js/main.js
I hope this is enough information to get you started with swfupload. Happy coding :)