mramardeepsingh Posted May 15, 2009 Share Posted May 15, 2009 hi, i have facing a problem with my video encoding site, i have 2 pages, 1st one is a form which is used to upload the video and fill out the details about the video like video title, summary etc. after uploading, once the submit button is clicked, the page 2 steps in, it contains the actual conversion progress bar. once the conversion is over, i want that page should redirect to another page where i can display the "Success" message, but its not redirecting. i have used header("location:user_video_upload_container.php?msg=" .urlencode("Video uploaded successfully & will be available online after approval")); exit(); but still its not redirecting. below is the complete code of the page. i will appreciate that if anybody can help me out with the redirection. thanks. <?php set_time_limit(1800); ob_implicit_flush(true); include_once "__init.php"; include_once "user__authenticate.php"; $mysql = new Mysql(); $user = new User(); $validation = new Validation(); $string = new String(); $file = new File(); $form = new Form(); $form->saveViewState("video_upload"); $user_id = $user->getUserId(); $video_uploader_name = $user->getUserName(); $video_name = $string->formatInput($_POST['video_name'], 1, "None"); $cat_id = $string->formatInput($_POST['cat_id'], 1, "None"); $summary = $string->formatInput($_POST['summary'], 1, "None"); $uploaded_new_filename = $string->formatInput($_POST['uploaded_new_filename'], 1, "None"); $uploaded_orig_filename = $string->formatInput($_POST['uploaded_orig_filename'], 1, "None"); if($validation->isEmpty($uploaded_new_filename) || $validation->isEmpty($uploaded_orig_filename)) { header("location:user_video_upload_container.php?msg=" .urlencode("Please upload a video")); exit(); } if($validation->isEmpty($video_name) || $validation->isEmpty($cat_id) || $validation->isEmpty($summary)) { header("location:user_video_upload_container.php?msg=" .urlencode(WEBSITE_INCOMPLETE_DETAILS)); exit(); } if(strlen($summary) > VIDEO_UPLOAD_SUMMARY_TEXT) { header("location:user_video_upload_container.php?msg=" .urlencode("Summary - Max ". VIDEO_UPLOAD_SUMMARY_TEXT ." characters are allowed")); exit(); } $target_filename = $string->generateRandomString(; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo WEBSITE_SEO_TITLE; ?> - ENCODING VIDEO .........</title> <?php include_once "_site_headtag.php"; ?> </head> <body style="margin:0px; padding:0px;"> <table cellpadding="0" cellspacing="0"> <tr> <td> <span class="static_sub_heading">Please wait while Video is encoding......</span> <br /><br /> PLEASE DO NOT NAVIGATE AWAY FROM THIS SCREEN OR CLOSE YOUR BROWSER BEFORE THE ENCODING HAS BEEN COMPLETED. <br /><br /> <? $Command = "\"" . PATH_TO_ENCODER."\" " . "\"" . WEBSITE_UPLOADS. "/temp/". $uploaded_new_filename ."\" " . "\"" . WEBSITE_UPLOADS. "/temp/". $target_filename .".flv\"" . " -vw " . VIDEO_WIDTH . " -vh " . VIDEO_HEIGHT . " -vz " . VIDEO_ZOOM_MODE . " -ac " . VIDEO_CHANNELS . " -tn " . "\"" . WEBSITE_UPLOADS . "/temp/". $target_filename .".jpg\" " . " -tw " . VIDEO_THUMB2_WIDTH . " -th " . VIDEO_THUMB2_HEIGHT . " -tf " . VIDEO_THUMBNAIL_POINT . " -vb 400"; // Use Windows path style so fvec.exe can handle it correctly. $Command = str_replace("\\", "/", $Command); //echo("<p>Executing command: <br />$Command</p>"); //echo("<br />"); // We do not use exec() because we want to get the Stdout line by line. //$StdOut = exec("\"$Command\"", $Lines, $ExecResult); $GotOutput = false; $ExecResult = -1; $CrLf = "\n"; $FirstLine = true; $RegExPattern = "([0-9]+)"; $descriptorspec = array( 0 => array('pipe', 'r'), // stdin is a pipe that the child will read from (we do not use it). 1 => array('pipe', 'w'), // stdout is a pipe that the child will write to and we will read from. 2 => array('pipe', 'w') // stderr is a file to write to (we do not use it). ); $process = proc_open("$Command", $descriptorspec, $pipes); if (is_resource($process)) { while(!feof($pipes[1])) { $InputLine = fgets($pipes[1], 1024); if (strlen($InputLine) == 0) break; $GotOutput = true; if(strcmp(substr($InputLine, 0, 6), "Error:") == 0) { echo("<font color=\"#ff0000\">" . $InputLine . "</font><br />" . $CrLf); break; } if(strcmp(substr($InputLine, 0, 9), "Percent: ") == 0) { if($FirstLine) { $FirstLine = false; echo("<p><table width=\"404\" bgcolor=\"#000000\" border=\"0\" cellspacing=\"0\" cellpadding\"1\"><tr><td>" . $CrLf); echo("<table width=\"100%\" bgcolor=\"#ffffff\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\"><tr><td><img id=\"bar\" src=\"images/bar.gif\" width=\"0\" height=\"10\" alt=\"Progress\"></td></tr></table>" . $CrLf); echo("</td></tr></table></p></td></tr></table>" . $CrLf); //echo(str_repeat(' ', 256)); ob_flush(); flush(); } $Matches = NULL; ereg($RegExPattern, $InputLine, $Matches); if(count($Matches) > 1) { // display the current encoding progress $Percent = $Matches[0]; echo("<script language=\"javascript\">document.all(\"bar\").width = " . ((int)$Percent * 4). "</script>" . $CrLf); ob_flush(); flush(); } } else { if(strcmp(substr($InputLine, 0, 9), "Duration:") == 0) { // get the duration of the input video. //$Duration = StringToTime(trim(substr($InputLine, 10))); } } } // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); // get the exit code of fvec.exe. //echo "Exit Code: "; $ExecResult = proc_close($process); } if($ExecResult == '0') { $sql = "select cat_id from ". TABLE_CATEGORIES ." where name='$cat_id' LIMIT 1"; $query = $mysql->query($sql); $row = $mysql->fetchArray($query); $cat_id = $row["cat_id"]; $sql = "insert into ". TABLE_VIDEOS." "; $sql .= "(video_name, user_id, type, cat_id, summary, datecreated) VALUES"; $sql .= "('$video_name', $user_id, 1, $cat_id, '$summary', now())"; if ($query = $mysql->query($sql)) { $id = mysql_insert_id(); // Move Video $videopath = $id.".flv"; $existing_video_path = WEBSITE_UPLOADS. "/temp/". $target_filename .".flv"; $new_video_path = WEBSITE_UPLOADS. "/videos/". $videopath; rename($existing_video_path, $new_video_path); $file->deleteFile(WEBSITE_UPLOADS. "/temp/". $uploaded_new_filename); // Move Thumb $imagepath2 = $id.".jpg"; $existing_image_path = WEBSITE_UPLOADS. "/temp/". $target_filename .".jpg"; $new_image_path = WEBSITE_UPLOADS. "/videos/thumbs/". $imagepath2; rename($existing_image_path, $new_image_path); // Generate Small Thumb $thumb = new Thumbnail($new_image_path); $thumb->resize(VIDEO_THUMB1_WIDTH, VIDEO_THUMB1_HEIGHT); $thumb->save(WEBSITE_UPLOADS."/videos/thumbs/".$id."_small.jpg", IMAGE_THUMB_QUALITY); $imagepath = $id."_small.jpg"; $ffm = new ffmpeg_movie($new_video_path); $duration = $ffm->getDuration(); $sql = "update ". TABLE_VIDEOS." set imagepath='".$imagepath."', imagepath2='".$imagepath2."', videopath='".$videopath."', duration='".$duration."', status=". USER_VIDEO_UPLOAD_APPROVAL_STATUS .", upload_status=1 where video_id=$id"; $query = $mysql->query($sql); $form->clearViewState("video_upload"); //$user->sendNewVideoAlert($video_uploader_name, $id, $video_name, "Video"); header("location:user_video_upload_container.php?msg=" .urlencode("Video uploaded successfully & will be available online after approval")); exit(); echo "<br /><br /><span class=\"star\">Video Uploaded Successfully, Will be available after approval.</span>"; } ?> <table cellpadding="0" cellspacing="0"> <tr> <td valign="middle"> <?php } else { $file->deleteFile(WEBSITE_UPLOADS. "/temp/". $uploaded_new_filename); $file->deleteFile(WEBSITE_UPLOADS. "/temp/". $target_filename .".flv"); $file->deleteFile(WEBSITE_UPLOADS. "/temp/". $target_filename .".jpg"); echo("<font color=\"#ff0000\">Error: failed to encode the file. The exit code is $ExecResult</font><br />" . $CrLf); } //ob_end_clean(); header("location:user_video_upload_container.php?msg=" .urlencode("Video uploaded successfully & will be available online after approval")); exit(); ?> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
BK87 Posted May 17, 2009 Share Posted May 17, 2009 all redirection have to be done before any html or any characters are printed on the page... rearange your code... Quote Link to comment Share on other sites More sharing options...
mramardeepsingh Posted May 20, 2009 Author Share Posted May 20, 2009 but in my case, i want to have the redirection after the html characters are printed. is there any way to force the redirection to a new page? Quote Link to comment Share on other sites More sharing options...
dzdrazil Posted May 20, 2009 Share Posted May 20, 2009 PHP redirects via the header, which by all standards must come before html. Therefore, to achieve what you want, use Javascript to redirect the browser after a few seconds. If you're not terribly familiar with Javascript, learn the syntax quick then pick up either the Jquery or some similar library to make things easier. You'll thank yourself if you do because libraries like Jquery handle all the browser inconsistencies for you- attempting to write javascript for all browsers without is foolhardy at best, given the amount of time you'll take re-inventing the wheel. Quote Link to comment 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.