dongxixia6399 2015-08-28 05:19
浏览 53

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 ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!