Hii,

I am new to PHP world. I need to convert the video files into flv format.
I am having a problem in the code. Its not working. I dont know whats the problem. It gives error " Parse error: parse error in \script\uploadvideopro.php on line 63 "

Here is my code

<?php
$extension = "ffmpeg";
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
$extension_fullname = "/php5.3.5/ext" . "/" . $extension_soname; 
           
/*****************Get the path to Extention ****************/
$array_path = explode("/",$_SERVER['SCRIPT_FILENAME']);
$dynamic_path = "";
for ($i=0;$i<sizeof($array_path)-1;$i++)
if($array_path[$i]!="")
$dynamic_path =$dynamic_path."/".$array_path[$i];
/******************set folders*****************************/
$flvpath = "C:/flvfiles";
$moviepath = "C:/movies" ;
//chmod($moviepath,0777);
//chmod($flvpath,0777);
/******************Upload and convert video *****************************/
if(isset($_FILES['cert_file']))
{
echo "<pre>".print_r($_FILES, true) . "</pre><br/>";
$fileName = $_FILES["cert_file"]["name"];
$fileNameParts = explode( ".", $fileName );
$fileExtension = end( $fileNameParts );
$fileExtension = strtolower( $fileExtension );
if(isset($_FILES['cert_file']))
{
if($fileExtension=="avi" || $fileExtension=="wmv" || $fileExtension=="mpeg"|| $fileExtension=="mpg" || $fileExtension=="mov" )
{
if ( move_uploaded_file($_FILES["cert_file"]["tmp_name"],$moviepath.$_FILES["cert_file"]["name"]))
{
  if( $fileExtension == "wmv" ) 
  {
      exec("ffmpeg -i ".$dynamic_path."/".$moviepath."".$fileName." -sameq -acodec mp3 -ar 22050 -ab 32 -f flv -s 320x240 ".$dynamic_path."/".$flvpath."myflv.flv");
  }
if( $fileExtension == "avi" || $fileExtension=="mpg" || $fileExtension=="mpeg" || $fileExtension=="mov" )
{
  exec("ffmpeg -i ".$dynamic_path."/".$moviepath."".$fileName." -sameq -acodec mp3 -ar 22050 -ab 32 -f flv -s 320x240 ".$dynamic_path."/".$flvpath."myflv.flv");

}
/******************create thumbnail***************/
exec("ffmpeg -y -i ".$dynamic_path."/".$moviepath."".$fileName." -vframes 1 -ss 00:00:03 -an -vcodec png -f rawvideo -s 110x90 ".$dynamic_path."/".$flvpath."myflv.png");
}
else
{
die("The file was not uploaded");
}
}
else
{
die("Please upload file only with avi, wmv, mov or mpg extension!");
}
}
else
{
die("File not found");
}
?>    //line number 63

I am not getting where is the problem...Any advice will be highly appreciated.

Thanks in advance

Dani AI

Generated

As and suggested, the parse error points to a syntax problem — most commonly a missing closing brace before the end of the file. A quick way to confirm is to run PHP's linter; it reports the exact parse complaint and line number:

php -l uploadvideopro.php

If that shows a "syntax error, unexpected end of file" then add the missing } just before the closing ?>. Also reformat/indent the whole file so matching if/else blocks are visually obvious; that usually prevents this class of errors.

A few additional issues in the posted code are worth addressing while fixing the syntax:

  • Path concatenation is fragile on Windows when the folder string lacks a trailing slash. Normalize paths with rtrim() + DIRECTORY_SEPARATOR before appending filenames.
  • Shell commands should use quoted/escaped paths to handle spaces and avoid injection. Build the ffmpeg command with escapeshellarg() and capture the exit code to detect failures.
  • Check the upload result details rather than only relying on move_uploaded_file(); inspect $_FILES['cert_file']['error'] and use is_uploaded_file() for safer checks.

Example patterns (small, safe snippets to adopt):

$moviepath = rtrim('C:/movies', '/\\') . DIRECTORY_SEPARATOR;
$dest = $moviepath . $fileName;
if (!move_uploaded_file($_FILES['cert_file']['tmp_name'], $dest)) {
    error_log('move_uploaded_file failed: ' . print_r($_FILES['cert_file'], true));
}
$ffmpeg = 'C:/ffmpeg/bin/ffmpeg.exe';
$cmd = escapeshellarg($ffmpeg) . ' -i ' . escapeshellarg($dest) . ' -f flv ' . escapeshellarg('C:/flvfiles/myflv.flv');
exec($cmd, $out, $rc);

Final checks: enable error_reporting(E_ALL)/display errors or tail the server error log, verify folder write permissions, confirm the ffmpeg executable path, and remove duplicate isset($_FILES['cert_file']) nesting. These steps will both fix the parse error and make the conversion flow more robust.

Recommended Answers

All 2 Replies

It looks like you might be missing a } at the end of the code, so it is getting confused when you suddenly end the php. I find it always helps to hit tab when starting a new block of code, so you can keep track of where you are up to :)

Member Avatar for Member #120589

Ditto. Indenting your lines will help keep track of the brackets.

if(){
   if(){
      
   }elseif(){

   }else{
      if(){

      }
   }
}

Something like that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.