AJAX不会执行所有的PHP代码

时间:2016-09-26 23:40:11

标签: javascript php ajax ffmpeg

我希望在上传视频文件时显示进度条。我正在使用JS和AJAX来跟踪文件上传php的进度,并发送文件。 php文件包含一个ffmpeg命令,用于从视频中获取一些帧。本质上,php文件创建一个随机文件夹,并将视频和帧放入其中。当if(isset($_FILES['file']))调用php时,它工作得很好。但是当我尝试使用AJAX时,它只上传视频,但忽略了ffmpeg命令和mysql_query。

使用Javascript:

function uploadFile(){
        var file = _("file1").files[0];
        var formdata = new FormData();
        formdata.append("file1", file);
        var ajax = new XMLHttpRequest();
        ajax.upload.addEventListener("progress", progressHandler, false);
        ajax.open("POST", "upload.php");
        ajax.send(formdata);

upload.php的

        $name = $_FILES['file1']['name'];
        $type = explode(".",$name);
        $type = end($type);
        $tmp = $_FILES['file1']['tmp_name'];
        $uploadOk = 1;
        $exp = explode(".",$name);
        $filename = rand().$exp[0];
        $path = "videos/" . $filename . "/" . $name;
        $ffmpeg = "/usr/local/bin/ffmpeg";
        $size = "320x180";

        if($type != 'mp4' && $type != 'MP4'){

          $message = "Only mp4 format is supported!";
          $uploadOk = 0; 

        }else{

          mkdir("videos/".$filename);

          // ffmpeg function 
          for($num = 1; $num <= 15; $num++){
          $interval = $num * 3;
          shell_exec("$ffmpeg -i $tmp -an -ss $interval -s $size /videos/$filename/thumb$num.png");}

          move_uploaded_file($tmp, $path);
          mysql_query("INSERT INTO table (name, url) VALUES('$name', '$path')");

为什么AJAX不执行完整的PHP?

0 个答案:

没有答案