Andrew
Andrew

Reputation: 238727

Trying to find an AJAX file upload solution for Zend Framework using jQuery

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!

Upvotes: 7

Views: 13398

Answers (7)

Gregory Pakosz
Gregory Pakosz

Reputation: 70204

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.

Upvotes: 7

Christof Coetzee
Christof Coetzee

Reputation: 57

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!

Upvotes: 0

Strae
Strae

Reputation: 19445

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]

Upvotes: 3

Andrew
Andrew

Reputation: 238727

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.

Upvotes: 0

Mayuresh
Mayuresh

Reputation: 1072

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

Upvotes: 0

denadai2
denadai2

Reputation: 31

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

Upvotes: 2

karim79
karim79

Reputation: 342635

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.

Upvotes: 4

Related Questions