How to convert mp4 files into mp3 on button click using ffmpeg/php?

前端 未结 1 1992
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 06:10

I am working on a php code as shown below where I am converting mp4 files into mp3 using system command ffmpeg (in the case stateme

1条回答
  •  鱼传尺愫
    2020-12-07 06:46

    The best way is to use XMLHttpRequest with better example here AJAX - Server Response

    Create a javascript function like this :

    
    

    Add somewhere something to handle the response of the server as you want; example:

    Modify the button to call the javascript function onclick="go('', this); return false;":

    
    

    Take the time to learn how works Ajax call, it's really important to communicate with the server if you don't use form

    You can use JQuery but it's better without ;)

    Edit

    Using form, you can do this:

    Edit :

    Replace $key by the House Number basename($file, ".mp4")

    and the page.php or your_encoder.php as you want for an Ajax call :

    // EXAMPLE FOR AJAX CALL
    
    "
          . $result;
    } else {
        echo "The file $filePath does not exist";
    }
    ?>
    

    If you use form, you have to:

    1. check if $_POST['key'] exists

    2. do the encoding if key exists

    3. send your new html table.

    // EXAMPLE FOR FORM CALL
    
    
    

    Edit :

    I know this adapted from your preview question but this code is "uncorrect", it works, no problem, but it can be optimized like this :

    from...

    
    

    ... to

    
    

    0 讨论(0)
提交回复
热议问题