bootstrap fileinput php上传集成

iam trying to get this sample working for me.

http://webtips.krajee.com/ajax-based-file-uploads-using-fileinput-plugin/

Pictures will be shown, but i get only the response "internal error" for every picture (no further information) and no files are uploaded.

index.html

<input id="images" name="images[]" type="file" multiple=true class="file-loading">    

<script> 
var $input = $("#images");
$input.fileinput({
uploadUrl: "upload.php",
uploadAsync: false,
showUpload: false, 
showRemove: false, 
minFileCount: 1,
maxFileCount: 5,
overwriteInitial: false,
uploadExtraData: function() {
    return {
        userid: 100,
        username: 'thomas'
    };
}
}).on("filebatchselected", function(event, files) {
$input.fileinput("upload");
});

upload.php

<?php

if (empty($_FILES['images'])) {
echo json_encode(['error'=>'No files found for upload.']);
return; 
}

$images = $_FILES['images'];
$userid = empty($_POST['userid']) ? '' : $_POST['userid'];
$username = empty($_POST['username']) ? '' : $_POST['username'];

$success = null;
$paths= [];
$filenames = $images['name'];

for($i=0; $i < count($filenames); $i++){
$ext = explode('.', basename($filenames[$i]));
$target = "uploads" . DIRECTORY_SEPARATOR . md5(uniqid()) . "." .    array_pop($ext);
if(move_uploaded_file($images['tmp_name'][$i], $target)) {
    $success = true;
    $paths[] = $target;
} else {
    $success = false;
    break;
}
}

if ($success === true) {
save_data($userid, $username, $paths);

$output = [];
} elseif ($success === false) {
$output = ['error'=>'Error while uploading images. Contact the system administrator'];

foreach ($paths as $file) {
    unlink($file);
}
} else {
$output = ['error'=>'No files were processed.'];
}

echo json_encode($output);

?>

Has anyone an idea whats wrong ?