Posts: 726
Name: John
Location: United States of America, California
|
I want to finish my code so that it has ways of dealing with errors
Blue is if worked red is if there was an error
CODE IS INCLUDED
There is more than one thing that needs to be corrected by error handling in the same program
I first need my script to validate. If all the fields are filled in, and the upload file has an except able extension ("which the program checks in a text file which is located at http://www.technologyforever.com/goodfiles.txt with one extension without the do per line.
If successfully it needs to upload the file and go to the next step
If it fails because the extension is not allowed it needs to say "This format is not allowed", Or if it fails because not all fields are filled in. it needs to say "please complete the entire form" and try again
Then after uploading it needs to convert the video using the exec function in php with ffmpeg a command line video converter
If successfully converted go to next step and add information to the mysql database.
If it fails it needs to show the message that says "there was an error please contact support" and stop the script from continuing.
If it successful show a message that says "your video has been successfully added."
If it it has a problem writing to mysql database it needs to try to write to the database again, and if that fails just show a message that says please try again later.
PHP Code:
<?php
//upload video $path= "uploadvidd/".$HTTP_POST_FILES['ufile']['name']; if($ufile !=none) { if (file_exists($path)) { $path= "uploadvidd/1".$HTTP_POST_FILES['ufile']['name']; } if(is_video($HTTP_POST_FILES['ufile']['tmp_name'])){
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { $input = $_GET['input']; list($usec, $sec) = explode(' ', microtime()); $output = str_replace('.', '', (float)$usec + (float)$sec);
//video converter script for use on TechnologyForever.com which uses ffmpeg //Do this if this part if upload is successful $ffmpeg = '/usr/bin/ffmpeg';//location of ffmpeg binary $bitrate = '32';//bitrate for audio options are 16,32,64 $ext = '.flv';//Extension of output video files $extb = '.jpg';//Extension of image $vidsize = '320x240'; //video size $imgsize = '150x100';//image size for menu $force = 'flv';//Force video format to $sstime = '00:00:35';//time to take screenshot $samprate ='22050'; // Sample rate choices are as follows 11025, 22050, 44100) //Converts uploaded video with FFmpeg binary exec('$ffmpeg -i /home/forbushj/public_html/uploadvidd/'.$vidIN.' -ar $samprate -ab $bitrate -f flv -s $vidsize /home/forbushj/public_html/vidd/'.$vidout.'.$ext.'); //Creates an image from a frame at time given on $sstime exec('$ffmpeg -i /home/forbushj/public_html/vidd/'.$vidout.''.$ext.' -s $imgsize -an -ss $sstime -an -r 1 -vframes 1 -y -f image2 /home/forbushj/public_html/pic/video/'.$vidout.'.$extb.');
IF this is successful I want it to write the information to a database if it is not successful I want to show an error message
//write to mysql $linkID = @mysql_connect("HOST","USER ","PASSWORD") or die("Could not connect to MySQL server"); @mysql_select_db("forbushj_onetest") or die("Could not select database"); // Retrieve the posted product information. $titlev = stripslashes($_POST['vidname']); $descrv = stripslashes($_POST['viddes']); $srcv = stripslashes($_POST['srcof']); $result = mysql_query(" INSERT INTO video ( title, descr, pic, locat, src ) VALUES ( '" . mysql_real_escape_string($titlev) . "', '" . mysql_real_escape_string($descrv) . "', '" . mysql_real_escape_string($output) . ".jpg', '" . mysql_real_escape_string($output) . ".flv', '" . mysql_real_escape_string($srcv) . "' ) ");
?>
OLD CODE
PHP Code:
<?php $dsrptn = 'upload your videos to TechnologyForever.com'; $sect = 'Videos'; $what = 'Upload your videos'; include 'head.php'; ?>
<?php //set where yzzou want to store files //in this example we keep file in folder upload //$HTTP_POST_FILES['ufile']['name']; = upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif
//exec('ffmpeg -i /home/forbushj/public_html/'.$path.' -s 150x100 -an -ss 00:00:35 -an -r 1 -vframes 1 -y -f image2 /home/forbushj/public_html/pic/video/'.$output.'.jpg'); $ext = ".flv"; exec('ffmpeg -i /home/forbushj/public_html/'.$path.' -ar 22050 -ab 48 -f flv -s 320x240 /home/forbushj/public_html/vidd/'.$output.'.flv'); exec('ffmpeg -i /home/forbushj/public_html/vidd/'.$output.''.$ext.' -s 150x100 -an -ss 00:00:35 -an -r 1 -vframes 1 -y -f image2 /home/forbushj/public_html/pic/video/'.$output.'.jpg'); //exec('rm /home/forbushj/public_html/'.$path.''); //passwords and users changed intentionally $linkID = @mysql_connect("HOST","USER","PASSWORD") or die("Could not connect to MySQL server"); @mysql_select_db("forbushj_onetest") or die("Could not select database"); // Retrieve the posted product information. $titlev = stripslashes($_POST['vidname']); $descrv = stripslashes($_POST['viddes']); $srcv = stripslashes($_POST['srcof']); $result = mysql_query(" INSERT INTO video ( title, descr, pic, locat, src ) VALUES ( '" . mysql_real_escape_string($titlev) . "', '" . mysql_real_escape_string($descrv) . "', '" . mysql_real_escape_string($output) . ".jpg', '" . mysql_real_escape_string($output) . ".flv', '" . mysql_real_escape_string($srcv) . "' ) ");
} else { } } } function is_video( $f ){ $result = trim ( exec ('file -bi ' . escapeshellarg ( $f ) ) ) ; $TYPE = explode("/", $result); if($TYPE[0] == "video"){ return TRUE; } else{ return FALSE; } }
?> <table width="95%" height="431" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td width="10%" colspan="3"><div align="center"> <p>Your video should be upload if not please <a href="http://www.technologyforever.com/contact.html">contact us.</a></p> <p> </p> <p>Return to <a href="http://www.technologyforever.com/upload.php">video uploader</a></p> <p>Return to <a href="http://www.technologyforever.com/video1.html">video section</a></p> <p>Return to <a href="http://www.technologyforever.com">main page</a></p> </div></td> </tr> </table> <?php include 'foot.php'; ?>
Last edited by goheadtry; 10-10-2007 at 08:53 PM..
|