views:

82

answers:

1

I need to implement a feature where a user can paste one or more YouTube links, a PHP script then downloads all of them to the server, displays progress bar for each download and then inserts relevant information about them to database.

How should I go about implementing this... Is this achievable with just file_get_contents()? Or perhaps I should use cURL? And how would I implement the progress bar for each download process? I was thinking if you could do this with jQuery somehow.

Help appreciated. Thanks.

edit: Just for clarification: I do not need to know how to download a video from YouTube, just how to download multiple files and how to display a progress bar for each download.

edit2: To elaborate: The site is an archive site for an artist. If a video file, such as an interview or live performance doesn't already exist on the site, but exists on YouTube, the user can simply paste a link to this video file, the server then downloads this file to the server and from that point on it's archived and hosted on the server and then people can watch the videos on the site. I just need to know how to download multiple files simultaneously and display a progress bar for each download so that the user(s) can see when they're ready to be viewed.

A: 

You'll have to do this with cURL, as an AJAX call would not work across domains.

I would post the information to a script file via AJAX, cURL the file, and echo numbers to represent the progress until it is finished. That would require multiple AJAX calls to get a true progress indicator, but it would probably be easier to just use a static spinner and call it a day.

You could send another AJAX call when the file is uploaded to the same PHP file to make your database changes as well.

melee
The responseText and responseXML properties of an XMLHttpRequest aren't available until the request has finished loading. The [W3 spec](http://www.w3.org/TR/XMLHttpRequest/#switch-done) dictates that the responseText should contain the fragments of the loaded data "so far", but as far as I can tell from my tests it only gets modified when the request is done (readyState = 4). This may mean that a progress bar with one script is impossible.
Leafy
If the php function returns the status of the download, then you could make the call to the script, have it return the current status of the upload, set a timer, and make another request at which time a different value will be echoed. I think it could work.
melee