Results 1 to 13 of 13
  1. #1
    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 == ) {

            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$finalFile0644 );
        }
    }
    ?>
    The upload form:

    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
    Thanks

    Disclaimer: I did not write this script, rather have modified it to server my needs.

    EDIT: I have FFMPEG installed on my box.

  2. #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.

  3. #3
    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

  4. #4
    Join Date
    Jun 2003
    Location
    Proud She-Geek
    Posts
    1,723
    Instead of using

    PHP Code:
    echo $_FILES 
    try using

    PHP Code:
    print_r($_FILES
    $_FILES is an array - similar to $_POST - and if you're getting an error with the $_FILES array I don't believe you'll be able to see the debugging info with an echo.

  5. #5
    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." );
        } 
    You could replace that by stating:

    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.

  6. #6
    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.
    ...

  7. #7
    Join Date
    Mar 2006
    Posts
    984
    My post above was only as a suggestion.

  8. #8
    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)

  9. #9
    Join Date
    May 2009
    Posts
    766
    Quote Originally Posted by lonea View Post
    echo $encode_cmd then try to run that cmd in shell and see what happen
    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");

    The problem with running the command in the shell is that your user account will have a different environment than the web server, so you may not catch permission issues, etc.

  10. #10
    Join Date
    May 2009
    Posts
    766
    nvrmind...can't believe I got duped into replying...

  11. #11
    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>

  12. #12
    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>";
    ?>

  13. #13
    If you are getting blank page, it appears that the script was terminated before the upload is complete. Check your script execution time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •