gpt4 book ai didi

javascript - xmlhttprequest 请求已发送,但代码未执行?

转载 作者:行者123 更新时间:2023-12-02 16:29:49 25 4
gpt4 key购买 nike

所以,我正在使用从 WWW 下载的 jQuery 上传脚本。

这是我的 JavaScript 代码:

$(document).ready(function()
{
var settings = {
url: "upload.php",
method: "POST",
allowedTypes:"pdf,xls,doc,docx,xlsx",
fileName: "name",
multiple: true,
onSuccess:function(files,data,xhr)
{
$("#status").html("<font color='green'>Upload is successed</font>");

},
onError: function(files,status,errMsg)
{
$("#status").html("<font color='red'>Upload is failed: " + errMsg + "</font>");
},
showDelete:true,
deleteCallback: function(data,pd)
{
for(var i=0;i<data.length;i++)
{
$.post("delete.php",{op:"delete",name:data[i]},
function(resp, textStatus, jqXHR)
{
//Show Message
$("#status").html("<font color='red'>File deleted.</font>");
});
}
pd.statusbar.hide(); //You choice to hide/not.

}
};
$("#mulitplefileuploader").uploadFile(settings);

});

这是我的“upload.php”:

<?php
include_once("_assets/_pages/db.php");

$output_dir = "_files/";
if(isset($_FILES["myfile"]))
{
$ret = array();

$error = $_FILES["myfile"]["error"];
//You need to handle both cases
//If Any browser does not support serializing of multiple files using FormData()
if(!is_array($_FILES["myfile"]["name"])) //single file
{
$fileName = $_FILES["myfile"]["name"];
move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir.$fileName);
$ret[]= $fileName;
$sql = 'INSERT INTO `Files` (FileName, UploadDate, DownloadCount) VALUES ($filename, CURRENT_TIMESTAMP, 0)';
$db->query($sql);
}
else //Multiple files, file[]
{
$fileCount = count($_FILES["myfile"]["name"]);
for($i=0; $i < $fileCount; $i++)
{
$fileName = $_FILES["myfile"]["name"][$i];
move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName);
$ret[]= $fileName;
$sql = 'INSERT INTO `Files` (FileName, UploadDate, DownloadCount) VALUES ($filename, CURRENT_TIMESTAMP, 0)';
$db->query($sql);
}

}
echo json_encode($ret);
}
?>

我的 upload.php 没有将文件放入“_files/”,也没有将任何内容插入到我的数据库中?我做错了什么?

其他问题:您是否推荐任何其他设计良好( Bootstrap 友好)的 jQuery 文件上传处理程序?

最佳答案

我猜,如果没有显示文件...您的表单中可能会缺少 enctype="multipart/form-data"

关于javascript - xmlhttprequest 请求已发送,但代码未执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28411265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com