android6011 Posted March 27, 2007 Share Posted March 27, 2007 First I would like to thank the users here who have helped me to get this far. The script I am about to show you works fine with small videos (tested with like 30 seconds fine) but larger videos cause the browser to freezeup and then eventually it will go back to normal but the video wasnt uploaded or added to the playlist. The script reads a url from a form, gets a video from youtube, saves it to the server, adds the filename to a playlist and exits. Please dont be offended by the code you are about to see, I'm roughly new at this (2 1/2 years of on and mostly off) <? /* machination.no-ip.info */ /* include the standard headers */ include('header.php'); include('headers/connect.php'); /* checks to see if the video should be grabbed - should probly check for submit instead of variable */ if (isset($_POST['url'])) { /* The posted variables from the form */ $url = $_POST['url']; $track = $_POST['track']; $desc = $_POST['desc']; $handle = @fopen ($url, "r"); /* Find the download ticket so we can actually request the video special thanks to Pascal from mediapirate.org for this part */ if($handle){ while(!feof($handle)){ $code .= fread($handle, 1024); } fclose($handle); $expression = '/v=([A-Za-z0-9_-]+)/'; preg_match_all($expression,$url,$video); $expression = '/t\=([A-Za-z0-9_-]{5,})/'; preg_match_all($expression,$code,$ticket); /* Remove the spaces so that we can create a table cuz ive had problems with spaces also get a filename and stuff ready for the grab and save */ $badtags = array("v="); $urlp1 = str_replace($badtags, "", $video[0][0]); $random = (rand()%50000); $fullurl="http://www.youtube.com/get_video?video_id=".$urlp1."&".$ticket[0][0]; $filename="videos/".$random.".flv"; /* Get the file from the url and save it */ ob_start(); readfile($fullurl); $file = ob_get_contents(); ob_end_clean(); $fp = fopen($filename, 'wb'); fwrite($fp, $file); fclose($fp); print "<tr class=\"content\"><td colspan=\"2\">Thank You. Your Video has been added"; } /* this first part seems firmiliar - I think i did it up there, oh well, make a name for the playlist that the media player will use */ $badtags = array(" "); $playlist = str_replace($badtags, "_", "$track"); $playlistname="playlists/".$playlist.".xml"; $somecontent = "<video url=\"$filename\" desc=\"$desc\" />"; /* Write the new entry to the playlist for the specified song */ if (is_writable($playlistname)) { if (!$handle2 = fopen($playlistname, 'a')) { echo "Cannot open file ($playlistname)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle2, $somecontent) === FALSE) { echo "Cannot write to file ($playlistname)"; exit; } echo "Success, wrote ($somecontent) to file ($playlistname)"; fclose($handle2); } else { echo "The file $playlistname is not writable"; } } /* If the form hasnt been submited yet print it */ else{ print " <tr class=\"content\"><td colspan=\"2\"> <h2>Submit Video</h2><br><br> <form name=uploadvideo action=grab_video.php method=post> <b>This may take several minutes depending on the video size and length. Only YouTube URLs are currently supported. Be sure to select the correct song from the drop down list.</b><br><br> Video URL:<br> <input type=text size=60 name=url class=input> <SELECT NAME=\"track\" class=input> "; $query = "SELECT * FROM media ORDER BY 'id' DESC"; $result=mysql_query($query); $i=0; $num=mysql_numrows($result); while ($i < $num) { $track=mysql_result($result,$i,"track"); print "<OPTION VALUE=\"$track\">$track"; $i++; } print " </SELECT> <br>Enter a brief description. E.G <i>Bumblefoot Solo</i><br><input type=text size=60 name=desc class=input> <input type=submit class=input value='Submit Video' class=input><br><br> </form> Get the url from:<br> <img src=images/youtube.jpg> "; } Quote Link to comment https://forums.phpfreaks.com/topic/44437-script-dies-causes-browser-to-temporarily-lock-up/ Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 Try set_time_limit(900); will set the timeout portion to 900 seconds so the script does not timeout before it is finished. Quote Link to comment https://forums.phpfreaks.com/topic/44437-script-dies-causes-browser-to-temporarily-lock-up/#findComment-216056 Share on other sites More sharing options...
android6011 Posted March 27, 2007 Author Share Posted March 27, 2007 where should i put that? Quote Link to comment https://forums.phpfreaks.com/topic/44437-script-dies-causes-browser-to-temporarily-lock-up/#findComment-216171 Share on other sites More sharing options...
android6011 Posted March 27, 2007 Author Share Posted March 27, 2007 i put it at the top of the code and I get Warning: set_time_limit() has been disabled for security reasons in /home/www/machination.awardspace.com/grab_video.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/44437-script-dies-causes-browser-to-temporarily-lock-up/#findComment-216174 Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 That means your host disabled that feature for you. You may be SOL unless you talk to your host. You may want to review this, maybe there is an answer. http://us2.php.net/manual/en/ref.info.php#ini.max-execution-time Quote Link to comment https://forums.phpfreaks.com/topic/44437-script-dies-causes-browser-to-temporarily-lock-up/#findComment-216181 Share on other sites More sharing options...
android6011 Posted March 27, 2007 Author Share Posted March 27, 2007 so does my code look good? it is just the timeout that causes it to abort too early? Quote Link to comment https://forums.phpfreaks.com/topic/44437-script-dies-causes-browser-to-temporarily-lock-up/#findComment-216435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.