Results 1 to 13 of 13
-
01-28-2007, 03:32 AM #1Web Hosting Guru
- Join Date
- Oct 2003
- Location
- Aggie Land, Texas
- Posts
- 334
PHP script to convert Video files to Flash files
I am getting a blank white page when I attempt to upload a file, and no files is being uploaded, nor converted.
PHP Code:<?php
ini_set( "max_execution_time", "3600" ); // sets the maximum execution time of this script to 1 hour.
$fileName = $_FILES['message']['name']; // get client side file name
if( $fileName ) {
// Check File Type
$fileNameParts = explode( ".", $fileName ); // seperate the name from the ext
$fileExtension = end( $fileNameParts ); // part behind last dot
$fileExtension = strtolower( $fileExtension ); // reduce to lower case
if( !$fileExtension == "mpg" && !$fileExtension == "avi" && !$fileExtension == "mpeg" && !$fileExtension == "wmv" && !$fileExtension == "rm" && !$fileExtension == "dat" ) {
die( "Invalid Video Format." );
}
// Check File Size
$fileSize = $_FILES['message']['size']; // size of uploaded file
if( $fileSize == 0 ) {
die( "Sorry. The upload of $fileName has failed. The file size is 0." );
} else if( $fileSize > 10240000 ) { //10 MB
die( "Sorry. The file $fileName is larger than 10MB. Advice: reduce the file quality and upload again." );
} else {
$uploadDir = '/home/coconut/www/conversion/uploaded/'; // Where the temp file will go
$uploadFile = str_replace( " ", "", $uploadDir . $_FILES['message']['name'] ); // Get rid of spaces in the filename
$finalDir = '/home/coconut/www/conversion/converted/'; // Where the final file will go
$finalFile = str_replace( " ", "", $finalDir . $fileNameParts[0] . ".flv" ); // Get rid of spaces in the filename
if ( !move_uploaded_file( $_FILES['message']['tmp_name'], $uploadFile ) ) {
echo "Possible file upload attack! Here's some debugging info:\n";
echo( $_FILES );
}
$encode_cmd = "/usr/bin/ffmpeg -i $uploadFile -acodec mp3 -ar 22050 -ab 32 -f flv -author \"Clip Author\" -copyright \"Clip Copyright\" $finalFile";
exec( $encode_cmd );
unlink( $uploadFile );
chmod( $finalFile, 0644 );
}
}
?>
PHP Code:<form action="convert.php" method="post" enctype="multipart/form-data"> <input type="file" name="audio" size="42"> <input type="submit" name="audio_submit" value="Submit"> </form>
Disclaimer: I did not write this script, rather have modified it to server my needs.
EDIT: I have FFMPEG installed on my box.
-
01-28-2007, 06:08 AM #2New Member
- Join Date
- Apr 2006
- Posts
- 2
put several echo statements into the php code, and see if what your submitting is working in anyway
for example, the first one you could do is
Code:echo "$fileName";
the rest - look through the code to see where you should be getting values, if nothing, you might be able to trace why.
if that makes you none the wiser - did it work in the first place, with little modications?
If it had a different upload page, try use that instead, and see where you have gone wrong.
-
01-28-2007, 02:35 PM #3Junior Guru
- Join Date
- Dec 2004
- Location
- San Francisco Bay Area
- Posts
- 213
Yea put some echos in put also look at the upload error message codes. See http://www.php.net/manual/en/feature...oad.errors.php php has a default upload size of 4mb which isn't that large for video. You may be running into that limit.
Sizzling Web Design - Creator of EasyEstimates: Let your customers create complex estimates and orders on your web site.
Video Gallery Pro - Show your videos like a pro
-
01-28-2007, 05:53 PM #4Retired Moderator
- Join Date
- Jun 2003
- Location
- Proud She-Geek
- Posts
- 1,723
Instead of using
PHP Code:echo $_FILES
PHP Code:print_r($_FILES)
-
01-28-2007, 10:13 PM #5Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
PHP Code:if( !$fileExtension == "mpg" && !$fileExtension == "avi" && !$fileExtension == "mpeg" && !$fileExtension == "wmv" && !$fileExtension == "rm" && !$fileExtension == "dat" ) {
die( "Invalid Video Format." );
}
PHP Code:$extension_array = array("mpg", "avi", "mpeg", "wmv", "rm", "dat");
if (!in_array($extension_array)) {
die("Invalid Video Format.");
}
Much shorter if statement this way.
-
02-02-2007, 04:28 PM #6Junior Guru Wannabe
- Join Date
- Aug 2004
- Location
- El Salvador
- Posts
- 72
Thak you horizon for letting us know that people learn here... you are the best example.. but come on... what you're suggesting is way too far from the reason of this thread.... Congratulations anyway, i would have put the file types on an array too.
Now, returning to the subject:
DelPierro, you have to place a hidden field on your form called "MAX_FILE_SIZE", this field MUST preceed the file input field (http://www.php.net/manual/en/features.file-upload.php) otherwise the file doesn't get uploaded on many PHP configurations....
-
02-02-2007, 07:32 PM #7Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
My post above was only as a suggestion.
-
02-02-2010, 07:20 AM #8Web Hosting Master
- Join Date
- Feb 2004
- Location
- Toronto
- Posts
- 2,308
echo $encode_cmd then try to run that cmd in shell and see what happen
VimHost >> 30 Days Backup | cPanel + LiteSpeed + JetBackup | DMCA FREE!
20 Years in business ~ Premium Hosting in Toronto, Canada ~ 151 Front Street (Canadian owned and operated)
-
02-02-2010, 09:21 AM #9Web Hosting Master
- Join Date
- May 2009
- Posts
- 766
Or, use exec()'s optional arguments (the extra bit here just routes STDERR to STDOUT so you trap error messages as well):
PHP Code:exec("$encode_cmd 2>&1", $output, $status);
if ($status)
{
print_r($output);
die("Exited with status: $status");
}
-
04-15-2010, 02:04 PM #10Web Hosting Master
- Join Date
- May 2009
- Posts
- 766
nvrmind...can't believe I got duped into replying...
-
02-01-2011, 12:40 AM #11Disturbed
- Join Date
- Dec 2002
- Location
- Jackson, MI
- Posts
- 1,525
what does your form initialization string look like? (From the form you are uploading the file from). You need to ensure you have enctype="multipart/form-data", so for example
<form enctype="multipart/form-data" method="post" action="path/to/file.php">
...
</form>
-
02-02-2011, 12:43 AM #12Disabled
- Join Date
- Jan 2011
- Posts
- 304
dont try and use and entire script you found somewhere upload the file or select a file that is uploaded and then once thats covered
just run your ffmpeg convert in the shell_exec function and your done
shell_exec('ffmpeg convert goes here');
I would suggest you run the ffmpeg via command line before your place it in your script so you can verify you have that part right and you can try the following to make sure your shell_exec is functioning on your server correctly
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
-
02-02-2011, 03:22 AM #13Web Hosting Evangelist
- Join Date
- Sep 2008
- Posts
- 545
If you are getting blank page, it appears that the script was terminated before the upload is complete. Check your script execution time.