AJAX不会执行所有的PHP代码

I want a progressbar to be shown while a video-file is being uploaded. I'm using JS and AJAX to track progress of the file-upload php, and send the file. The php file contains a ffmpeg command that grabs some frames from the video. Essentially the php file creates a random folder, and puts both the video and the frames in it. when the php is called by if(isset($_FILES['file'])) it works just fine. But when i try to use AJAX it only uploads the video, but ignores the ffmpeg command and 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')");

Why dosen't AJAX execute the complete php?