I'm looking for examples (maybe on Github, blog, or elsewhere) that demonstrate how to upload files (videos) directly from a php http post form to AWS S3. The main requirement is to see the progress of the upload in action and trigger a response when complete (without reloading the page). jQuery File Upload Plugin could be a good solution, do you know of any code examples that do this? The files (videos) will be up to 1gb in size, so propose a different method if you think this won't work well.
You have checked this out, right?
Sadly, there's no progress involved by default. Probably you should do it yourself using AWS serverside API and ajax polling (or websockets), which would add workload for your server, though.
Here is a C# example of how to track the Multipart Upload Progress.
Otherwise you could go for a client-side approach with the Javascript SDK.
Related
http://www.plupload.com - "Allows you to upload files using HTML5 Gears, Silverlight, Flash, BrowserPlus or normal forms, providing some unique features such as upload progress, image resizing and chunked uploads." This is the uploader used in current WordPress v3.4.1 and the best one out there in my opinion.
It comes with upload.php file (full file: http://ideone.com/xbPUS).
I have doubts about its security: When I have upload.php on my server and even if I don't setup any Javascript for Plupload anyone is still able to relatively easy send request to upload.php file and upload anything, anytime... TRUE OR FALSE?
How do I prevent that?
It's not a security issue. Across the internet you can try to upload anything you want to servers (addresses) that support POST method. It's up to server-side software to accept or reject such upload - it's always been this way. Of course there can be some restrictions put onto who uploads what (using tokens, authorization etc), but that's up to you (as developer) to handle.
As to upload.php file from plupload, I think it's suppose to be just a quick and dirty example, that makes trying out plupload a little bit easier.
I think you want Wordpress to work with upload.php and not the other way arround. So if anyone would call upload.php directly it will fail. Can you set some specific information that will only be available from within your Wordpress functions. In upload.php you can ask for this information if not available it will stop. Hope this is what you need.
So far I've figured out HOW to upload files asynchronously with Ajax and PHP, no problem there. But I want to get the percentage of the file that's already been uploaded, as it's uploading, and, after hours of research, I can't find a good way to do this without cheating.
Some implementations I've seen used Flash to upload, and getting the percentage in Flash is apparently fairly common, but I'd like to avoid this if I can.
Any ideas?
The core problem is that RFC 1867, the specification for file uploads over HTTP via the multipart/form-data MIME type, does not provide any method for providing file upload progress.
A file upload is actually just a fancy form submit. CGI scripts, PHP, and all other web technologies that rely on a front-end web server to first accept the request might not actually begin executing until the entire upload has completed. This means that they generally can't even know when the upload has started, only when it's been completed.
New versions of PHP's APC extension include a workaround for this problem that performs some level of black magic that allows it to know about uploads earlier. It only works as part of mod_php, though. The devs don't seem to have plans to support it under FastCGI.
Another server-side option would be the "uploadprogress" PECL extension. I'm not entirely sure what kind of black magic it uses. The source suggests that it actually hooks into the processing of the multipart MIME parts. (This suggests that at least some SAPIs stream form data to PHP as the client uploads it. I know that at least some FastCGI servers buffer the entire request before passing it along, so this might not work for you. YMMV.)
Both of these options are for normal file uploads. Ajax -- or rather, XMLHttpRequest -- does not support file upload operations. Most of the workarounds in this area involve creating an iframe and submitting a form there, and that also implies someone else's client-side work. If you're going to go through that level of hoop jumping, you'd may as well use one of the modern file upload widgets.
Personally, I use Plupload, a Javascript widget that can work with everyone's favorite Javascript library, jQuery. Some others swear by Uploadify. Regardless, both of these widgets offer a high degree of user feedback as to upload progress. They are likely to be easier for you to implement than APC or uploadprogress and have the advantage of being built and tested thoroughly by other people.
Plupload supports multiple upload engines, including HTML5, Gears, Flash, Silverlight, oldschool HTML4 and more. Between HTML5, Flash and Silverlight, you've pretty much just covered 100% of your audience. It also allows you to subscribe to events and have your own code perform magic. For example, if you need server-side file upload progress information, you can have the client regularly send updates to a different script. This would be useful if you regularly have clients uploading huge files and you want to know about it in real time.
tl;dr: Uploading is hard, let's go client-side!
Yeah,I dont like that "cheating" method either, In my opinon, the best method is to use APC , and its method, apc_fetch
Using ajax to make a apc_fetch, with a unique key specifying the upload, will return what you need .. ie bytes uploaded / total bytes.
Then simply do a progress bar with javascript.
I have heard chrome and safari dont allow you to do ajax calls during post upload, the work arround includes using an iframe to do the calls with the apc identifier.
I'm trying to figure out if there's a way to get the progress of a file upload with PHP and/or Kohana. My script can upload images, videos, zip, exe, whatever I want really. However the larger the file the longer the user has to wait without any indication.
I was hoping to use some AJAX here to initialise the upload and then report back the progress.
Is this possible with PHP... and can anyone give me an indication of where to start looking.
there is a file upload progress extension for php, see http://www.ultramegatech.com/blog/2010/10/create-an-upload-progress-bar-with-php-and-jquery/ for how to use it.
I like to use a server module to do this sort of thing, mainly because it makes my life as a web developer easier if all I need to do is grab upload statistics from a URL. Nothing has to be changed in your website.
For Nginx there is the Upload Progress module and it should work on all recent releases. You can find code examples on the Nginx Wiki: http://wiki.nginx.org/HttpUploadProgressModule
For Apache there is the Upload Progress too. I haven't used it myself, but it seems fairly straight forward.
If you don't have access to the server configuration, then you might want to fall back onto a pure flash / javascript solution. For this I had good luck with Uploadify in the past, but it requires a bit more work as you now have to upload files in a separate request. Someone should be able to suggest a good HTML5 upload progress plugin too.
you could do this also with apache and APC example
I am looking for a decent file uploader. I'm using django, but while i don't NEED a django file uploader, python is preferable. php would also be fine.
can anyone point me in the direction of a good file uploader which is secure and efficient?
EDIT: I need the server-side handler of file uploads.
Agree with jeerose: Uploadify is a nice app.
I've made a simple Django wrapper for it as well if you're interested: django-uploadify. It basically gives you a template tag which renders uploadify and fires a Django signal whenever a file is received.
How you implement the 'handler' you mentioned above is simply a matter of subscribing to the signal and then doing whatever you wish with the incoming data. (the wiki includes an example of creating a new File Model if that's the kind of thing you're looking for)
I'm using uploadify which is an upload plugin for jQuery with a flash progress bar. I use some basic php for the upload script. It can be made as secure as you need with a little investigating the forum.
here is my situation:
I want to create an AJAX file-upload script, which will upload to an external site (ie: not the one the script is located in) and at the same time report the progress of the upload. How would I go about doing this? Note that the process must be secure.
If you are POSTing the file to another server there is no way to know the status of this upload since the upload is done between the users browser and the remote site.
If you have access to the script that handles file upload on the other site you could use Zend_File_Transfer and Zend_ProgressBar to fetch the information on the uplad progress from the other site and display it on your page.
Note: to use Zend_ProgressBar you need APC or uploadprogress extension.
There are two ways to do:
Using ajax and CGI
Using flash
The advantage of the flash method is that it does not require you to rewrite any server side scripts. This is especially good if you upload to a different server than yours. You do need to put a cross domain xml file on that server though.
The advantage of the ajax version is that it does not require your users to have flash installed.
There is no way to get the exact progress using ajax and php. Using php and ajax you can only know wheather the upload is in progress or finished. That is the reason why all ajax/php aplications have loading but no progress bar. If you explicitly want progress bar you should use a PERL CGI
Flash ( swfupload ) is probably the easiest. Vimeo.com uses swfupload to achieve this as well. Ihe only other method I know of involves php and APC which a tutorial of can be found at http://phpriot.com/articles/php-ajax-file-uploads.