尝试使用 jQuery 为 Zend Framework 找到 AJAX 文件上传解决方案

发布于 2024-07-16 15:30:49 字数 189 浏览 11 评论 0原文

我正在尝试创建一个“上传文件,并将电子邮件作为附件”表单,其中文件在选择后(如 Gmail)开始上传,然后再发送电子邮件。 我还想实现一个进度条来显示上传的状态。

应该有各种各样的例子,但我就是找不到它们!

您知道任何示例、教程、插件、帮助程序吗?或者您自己做过这些并且想分享一些代码示例吗?

谢谢!

I'm trying to create an "upload file, and email as an attachment" form where the file starts uploading after it has been selected (like Gmail), before sending the email. I would also like to implement a progress bar to show the status of the upload.

There should be all sorts of examples out there, but I just can't find them!

Do you know of any examples, or tutorials, plugins, helpers, or have you done this yourself and would like to share some code samples?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

本宫微胖 2024-07-23 15:30:49

看看

还有一个例子将 fancyupload 与 Zend Framework 集成:虽然 fancyupload 基于 mootools,但您可以从解释的内容中学习。

注意:与fancyupload一样,uploadify使用flash。 但是,当闪存不可用时,它的性能会下降。

Have a look at

There is also an example of integrating fancyupload with Zend Framework: although fancyupload is based on mootools, you can learn from what's explained.

Note: as fancyupload, uploadify uses flash. However, it degrades when flash is not available.

彩虹直至黑白 2024-07-23 15:30:49

尝试使用 jQuery 表单插件,它支持ajax上传,示例可以在提供的链接。 Zend Framework 有一个 jQuery 助手

Try using the jQuery form plugin, which has support for ajax uploading, examples can be found on the link provided. Zend Framework has a jQuery helper.

七秒鱼° 2024-07-23 15:30:49

正如其他人所建议的,Jquery 有您需要的插件。

一个简单的 iframe 就可以解决问题,您需要 APC进度条。

这是一个“经过严格测试”的解决方案,例如 cms Drupal 使用它(不知道是否使用 jquery,但我了解 iframe 和 APC)。

一些教程:

Creating an Upload Progress Bar in PHP with APC

创建上传进度带 APC 的 PHP 栏:第 4 页中的 js/Ajax 部分

上传每个 APC + jQuery 的进度条(意大利语)

使用 PHP5、APC 和 jQuery 上传进度条

HOWTO:PHP 和 jQuery 上传进度条

PHP 中使用 AJAX 进度条异步文件上传

Zend 框架:文档(第 21.1.5 章) 文件上传进度)

编辑

我不会发布代码,因为没有用; 只需按照我发布的教程之一(例如第一个教程)进行操作,您就会找到所需的所有代码,并完整解释其用途(恕我直言,这比代码本身更重要)。

[OT]

停止这场愚蠢的下/上选票战争。 我们来这里不是为了赢得愚蠢的声誉,而是为了在编程技巧上互相帮助,对吗?

我并没有否决所有建议 Flash 解决方案的人,只是安德鲁的回答,因为它不太正确,并且不是对 swf“问题”的有用分析。

重点不在于我不喜欢闪光灯,而是闪光灯对于其他类型的问题(视频、音乐等)来说很好(不可或缺),但不是可靠的处理文件上传的解决方案,可以通过 Javascript 和 php 本身轻松完成的事情(使用 APC,如果您不能在服务器上使用 APC,则使用“flash 解决方案”)。

对于 swf 对象,您只需要希望处理它的“api”能够满足您的所有需求,否则..他们会给您源(.fla)文件吗? 您有 adobe flash 的许可证以及编辑它的知识吗? 您准备好每次您的精美上传需要更简单的修改了吗? 您同意我的观点,即查找 js 或 php 的帮助比查找 flash 的帮助最容易吗?

这就是为什么我不喜欢针对此类问题的闪存解决方案。

然后,请随意对我投反对票,我来这里是为了学习不要获得愚蠢的代表点。

[/加时]

As someone else suggested, Jquery has the plugin you need.

A simple iframe will do the trick, and you'll need APC for the progress bar.

This is an 'heavy-tested' solution, for example the cms Drupal use it (dont know if with jquery, but im sure about the iframe and APC).

Some tutorial:

Creating an Upload Progress Bar in PHP with APC

Creating an Upload Progress Bar in PHP with APC: js/Ajax part in page 4

Upload con progress bar per APC + jQuery (italian language)

Upload progress bar with PHP5, APC and jQuery

HOWTO: PHP and jQuery upload progress bar

Asynchronous file upload with AJAX progress bar in PHP

Zend Framework: Documentation (Chapter 21.1.5. Progress for file uploads)

EDIT:

I wont post the code becose is useless; just follow one of the tutorial i've posted (the first one, for example) and you'll find all the code you need with a full explanation of waht the cose do (that is more important than the code itself, imho).

[OT]

Stop this stupid down/up votes war. We are not here to win stupid reputation, but to help each other in programming skill, right?

I didnt downvote all whom suggested flash solution, just the andrew answer becose was kindly uncorrect and not a usefull analysis of the swf 'issue'.

The point is not that i dont like flash, but that flash is good (indispensable) for other kind of issues (video, music, etc..) but NOT a reliable solution for handling file uploads, things that can be easly done by Javascript and php itself (with APC, if you cant use APC on your server, then go with 'flash solution').

With swf object, you just have to hope that the 'api' to handle it fulfill all you needs, else.. do they give you the source (.fla) file? do you have a license of adobe flash, and the knowledges to edit it? Are you ready to do taht everytime your fancy upload need even the simplier modification? You agree with me that find help for js or php is easyest than finding help for flash?

Thats why i don like the flash solution for this kind of issues.

Then, feel free to keep you downvote on me, im here to learn not to gain silly rep point.

[/OT]

说好的呢 2024-07-23 15:30:49

我建议你使用jquery uploadify.com。 该示例在网站上。 您可以使用此 jquery 插件并将文件存储到数据库(可能是临时表)中。 当用户发送电子邮件时,您将获取文件、附加文件并将其从数据库中删除。

PS:如果您遇到一些会话问题,请执行以下操作:zend 框架丢失会话

I suggest you uploadify.com with jquery. The example is on the site. You can use this jquery plugin and store the file into the DB (maybe a temporany table). When the user will send the email you will fetch the files, attach it and delete it from the database.

PS: if you have some sessions problems take this: zend framework losing session

柠檬色的秋千 2024-07-23 15:30:49

您看过 http://digitarald.de/project/fancyupload/ 吗?
看起来可以满足你的要求。

Have you looked at http://digitarald.de/project/fancyupload/ ?
Seems to satisfy your requirements.

回忆凄美了谁 2024-07-23 15:30:49

SWFUpload 看起来很有前途:

优点:

  • 中按 ctrl/shift 选择一次上传多个文件
  • 通过在对话框中的Javascript 回调 事件
  • 在上传开始之前获取文件信息
  • 使用 XHTML 和 css 设置上传元素的样式
  • 使用 HTML 上传文件时显示信息
  • 无需重新加载页面
  • 适用于所有支持 Flash 的平台/浏览器。
  • 如果 Flash 或 javascript 不可用,优雅地降级为正常 HTML 上传形式
  • 上传开始前控制文件大小
  • 仅在对话框中显示选定的文件类型
  • 排队上传,在开始上传前删除/添加文件

甚至还有一个 SWFUpload jQuery 插件 使使用 SWFUpload 变得更加容易,以及有关的教程如何使用 SWFUpload jQuery 插件执行多个文件带进度条上传

缺点:

需要 Flash。 =/

另外,根据这篇博文

许多人在将 SWFUpload 与 Zend Framewok 结合使用时遇到的一个问题是,会话经常在上传过程中丢失。

但作者提供了使用 SWFUpload 和 Zend Framework 时丢失会话的解决方案。 这里还有一个 Stack Overflow 使用 SWFUpload 和 Zend Framework 时丢失会话的解决方案

SWFUpload looks promising:

Pros:

  • Upload multiple files at once by ctrl/shift-selecting in dialog
  • Javascript callbacks on all events
  • Get file information before upload starts
  • Style upload elements with XHTML and css
  • Display information while files are uploading using HTML
  • No page reloads necessary
  • Works on all platforms/browsers that has Flash support.
  • Degrades gracefully to normal HTML upload form if Flash or javascript is unavailable
  • Control filesize before upload starts
  • Only display chosen filetypes in dialog
  • Queue uploads, remove/add files before starting upload

There's even a SWFUpload jQuery Plugin to make working with SWFUpload even easier, and a tutorial on How to use the SWFUpload jQuery Plugin to do Multiple File Upload with Progress Bar

Cons:

Requires Flash. =/

Also, according to this blog post:

One issue many people run into when using SWFUpload with Zend Framewok is that sessions are often lost in the upload process.

But the author offers a solution to lost sessions when using SWFUpload and the Zend Framework. Here also is a Stack Overflow solution to lost sessions when using SWFUpload and the Zend Framework.

笑着哭最痛 2024-07-23 15:30:49

只是一个非常重要的注意事项 - 当使用 Flash 上传器时,文件 mime 类型不会传递到服务器,所有文件都将是 application/octet-stream - 这意味着您需要利用其他方法来查找真实类型...也许是exe文件已上传!

Just a very important note - when using Flash uploaders, the file mime type will not be passed to the server and all files will be application/octet-stream - meaning you need to utilize other methods to find the real type... maybe an exe file was uploaded!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文