By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Uploading Videos

P: 24
Hello everyone I am creating a project which will upload videos and play them. When a user uploads a video it will be convereted into .flv format. But the problem I have not been able to successfully upload and convert the videos. I have getting an error.

My code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ini_set( "max_execution_time", "3600" ); // sets the maximum execution time of this script to 1 hour.
  3. $fileName = $_FILES['audio']['name']; // get client side file name
  4.  
  5.  
  6. if( $fileName ) {
  7.     // Check File Type
  8.     $fileNameParts = explode( ".", $fileName ); // seperate the name from the ext
  9.     $fileExtension = end( $fileNameParts ); // part behind last dot
  10.     $fileExtension = strtolower( $fileExtension ); // reduce to lower case
  11.  
  12.     if( !$fileExtension == "mpg" && !$fileExtension == "avi" && !$fileExtension == "mpeg" && !$fileExtension == "wmv" && !$fileExtension == "rm" && !$fileExtension == "dat" ) {
  13.         die( "Invalid Video Format." );
  14.     }
  15.     // Check File Size
  16.     $fileSize = $_FILES['audio']['size']; // size of uploaded file
  17.     if( $fileSize == 0 ) {
  18.  
  19.         die( "Sorry. The upload of $fileName has failed. The file size is 0." );
  20.     } else if( $fileSize > 10240000 ) { //10 MB
  21.         die( "Sorry. The file $fileName is larger than 10MB. Advice: reduce the file quality and upload again." );
  22.  
  23.     } else {
  24.         $uploadDir = 'uploaded/'; // Where the temp file will go
  25.         $uploadFile = str_replace( " ", "",  $uploadDir . $_FILES['audio']['name'] ); // Get rid of spaces in the filename
  26.  
  27.         $finalDir = 'converted/'; // Where the final file will go
  28.         $finalFile = str_replace( " ", "",  $finalDir . $fileNameParts[0] . ".flv" ); // Get rid of spaces in the filename
  29.  
  30.         if ( !move_uploaded_file( $_FILES['audio']['tmp_name'], $uploadFile ) ) {
  31.             echo "Possible file upload attack!  Here's some debugging info:\n";
  32.             echo( $_FILES );
  33.         }
  34.  
  35.  
  36.         $encode_cmd = "/usr/bin/ffmpeg -i $uploadFile -acodec mp3 -ar 22050 -ab 32 -f flv -author \"Clip Author\" -copyright \"Clip Copyright\" $finalFile";
  37.         exec( $encode_cmd );
  38.  
  39.         unlink( $uploadFile );
  40.         chmod( $finalFile, 0644 );
  41.     }
  42. }
  43. ?>
The error:

Expand|Select|Wrap|Line Numbers
  1. Warning: chmod() [function.chmod]: No such file or directory in C:\wamp\www\Test\test2.php on line
Can someone please help me on this problem. Thanks in advance.
Sep 21 '08 #1
Share this Question
Share on Google+
5 Replies


Atli
Expert 5K+
P: 5,058
Hi.

One thing that that confuses me... you execute "/usr/bin/ffmpeg" to convert your file, but then you get a warning in a file at "C:/wamp/...".

The first would indicate that you are on a Unix server, but the second a Windows server.

Which is it?

If this is a Windows server, I would guess the command you are executing isn't working, seeing as it is trying to execute a file using a Unix path.
Sep 21 '08 #2

P: 24
Hi.

One thing that that confuses me... you execute "/usr/bin/ffmpeg" to convert your file, but then you get a warning in a file at "C:/wamp/...".

The first would indicate that you are on a Unix server, but the second a Windows server.

Which is it?

If this is a Windows server, I would guess the command you are executing isn't working, seeing as it is trying to execute a file using a Unix path.
Hello Atli thanks for replying. Yes I am using a Windows server.
Sep 21 '08 #3

Atli
Expert 5K+
P: 5,058
Then that command wouldn't work.

You would have to install and execute a Windows version of the "ffmpeg" application you are trying to use. That command looks like it is meant to be executed on some sort of a Unix server.

You would probably also have to provide absolute paths to the files you want to use in the command, rather than the relative paths you are currently using.
Sep 21 '08 #4

P: 24
Then that command wouldn't work.

You would have to install and execute a Windows version of the "ffmpeg" application you are trying to use. That command looks like it is meant to be executed on some sort of a Unix server.

You would probably also have to provide absolute paths to the files you want to use in the command, rather than the relative paths you are currently using.
So should I write the following code instead:

Expand|Select|Wrap|Line Numbers
  1. $encode_cmd = "ffmpeg -i $uploadFile -acodec mp3 -ar 22050 -ab 32 -f flv -author \"Clip Author\" -copyright \"Clip Copyright\" $finalFile";
Sep 21 '08 #5

Atli
Expert 5K+
P: 5,058
So should I write the following code instead:

Expand|Select|Wrap|Line Numbers
  1. $encode_cmd = "ffmpeg -i $uploadFile -acodec mp3 -ar 22050 -ab 32 -f flv -author \"Clip Author\" -copyright \"Clip Copyright\" $finalFile";
Does it work?
This is a shell command you are executing, so how it looks will depend on how your OS is configured. I can't tell you exactly what to do because I simply don't know enough about your system.

You need to have the ffmpeg application installed, and you need to call the executable, which means you need to know where it is. If the path to that file is in the PATH variable, then that might indeed work.

And like I said in the previous post, you will need to use absolute paths rather than the relative paths you used in your example.
Sep 21 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.