Quote:
Originally Posted by blacktiger786
hi chump i want add some limit on my script like i want when video increase 10 min lenght
or 10mb size its not convert what i do? please fast reply
|
Someone else was wanting a way to do this earlier, and I sent the following message to him/her at that time. Perhaps it will help you:
Quote:
I see 2 ways to get remote file size and cancel the download/conversion if the file is too big (per some predefined MAX_FILE_SIZE constant in your script):
1) Try the solution suggested here: http://www.codingforums.com/showpost...&postcount=112. That post links to some example code here: http://www.php.net/manual/en/functio...size.php#92462. This method allows you to gauge file size before actually downloading the file (by only downloading the HTTP headers).
2) Another way to do this is to leverage the CURLOPT_WRITEFUNCTION callback to gauge file size as the download is in progress. See these links:
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
http://curl.haxx.se/libcurl/php/examples/callbacks.html
The CURLOPT_WRITEFUNCTION callback receives the number of bytes written -- either since the last time the callback fired, or the total number of bytes received during the cURL session -- i'm not sure which.
If the CURLOPT_WRITEFUNCTION receives the total number of bytes received for the current download, then it's just a matter of returning something other than the number of bytes received inside the callback function -- when the total bytes received exceeds the maximum download size -- to force the cURL download to abort with an error. (This callback must return the number of bytes received in order to sustain the cURL process.)
If the CURLOPT_WRITEFUNCTION receives the number of bytes received since the last time the callback was executed, then the strategy is a little more complex. You'll need to set up a class field/variable to store the growing number of bytes downloaded. And every time the callback fires, you'll need to increment this class variable by the current number of bytes received by the callback -- and then check to see if the class variable exceeds your maximum download size. When your class variable exceeds maximum download size, after many calls to the callback function, then in the final call to the callback function you can return something other than the number of bytes received to cause the cURL process to abort.
Once you have determined that the downloaded file is too large, and you have aborted the cURL process, then you can delete the partially downloaded file off the server. And serve an error message to the user.
|
The person said he/she tried the above, but couldn't get it to work. (I haven't tried any of the above solutions, but in theory, it seems like they could work.) Instead, he/she offered the following alternative:
Quote:
I came up with a simple solution by using the duration of the video
Here is my code: http://pastie.org/private/t2tsxrxfd351ohbfd9njka
The first part extracts the video ID and the second part gets the length of it.
Once the length has been fetched it multiplies it with 23 which is the average size for 1 second on a medium quality FLV video. If the size then is larger than the limit it will echo an error.
|
I'm just quickly regurgitating an old conversation here and hoping you can glean some benefit from it. It seems like it applies to your situation...