gpt4 book ai didi

php - 提交成功但上传无法在合并表单中工作

转载 作者:可可西里 更新时间:2023-11-01 12:22:07 25 4
gpt4 key购买 nike

在尝试将提交和上传合​​并到一个表单中时,我在上传时遇到了问题,但对于提交表单来说没问题。

JQuery + Ajax:

$("#oqcsubmit").click(function() {
if($("#oqc").valid()) {
var params=$("#oqc").serialize();
$.ajax({
type:"post",
url:"doinput.php",
data:params,
cache :false,
async :false,
success : function() {
$(".dt").val("");
$(".stat").val("");
return this;
},
error : function() {
alert("Data failed to input.");
}
});
return false;
}
});

<form id="oqc" enctype="multipart/form-data" >
<input type="text" id="mod" name="mod" class="dt"/>
<input type="text" id="no" name="no" class="dt"/>
<input id="filename" name="uploadedfile" type="file" />
<input type="submit" id="oqcsubmit" value="Submit" />
<input type="hidden" name="action" value="oqcdata" />
</form>

PHP:

$dbc=mysql_connect(_SRV,_ACCID,_PWD) or die(_ERROR15.": ".mysql_error());
$db=mysql_select_db("QPL",$dbc) or die(_ERROR17.": ".mysql_error());

$target_path = "data/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
//print_r($_FILES);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else{
echo "There was an error uploading the file, please try again!";
}

switch(postVar('action')) {
case 'oqcdata' :
oqcdata(postVar('mod'),postVar('no'));
break;
}

function oqcdata($mod,$no) {

$Model = mysql_real_escape_string($mod);
$Serial = mysql_real_escape_string($no);

//build query
$sql = "INSERT INTO OQC (Model, Serial) VALUES ('".$Model."','".$Serial."')";
echo $sql;
$result=mysql_query($sql) or die(_ERROR26.": ".mysql_error());
echo $result;
mysql_close($dbc);

如何将上传代码正确地放在这个页面中?所以两者都可以工作。目录权限:chmod 777 data


文件在提交(不是发送)后留在表单中。 file lagging


更新

在切换之前移动上传代码后我得到了这个错误:

PHP Notice:  Undefined index: uploadedfile

这意味着表单不发送 uploadedfile 值。检查参数后,没有包含 uploadedfile。为什么会这样?甚至这个值也包含在表单中并使用 .serialize()

form data :
mod:KD-R321ED
no:177X1000 // where is the uploaded file value?
action:oqcdata

最佳答案

PHP Notice:  Undefined index: uploadedfile

it's mean that the form not send the uploadedfile value. After check the parameter there are no uploadedfile included. why it happens?

不能通过 vanilla 跨浏览器 ajax 上传文件,例如 jQuery 使用的那种。句号、句号、故事结尾。

如果您必须在不刷新页面的情况下进行上传,常用的技巧是创建一个 iframe 并将表单提交给它。另一个技巧是使用实验性的 File API , 作为 HTML5 的一部分公开。这些可能是您自己处理的痛苦,但如果您想全部手动完成,它应该会很有效。

强烈建议为此使用第三方文件上传小部件。我很幸运 Plupload ,但也有人推荐Uploadify .他们都可以选择使用 Flash 或 HTML5 后端来执行上传,这也为用户提供了一个快乐的小进度表。

关于php - 提交成功但上传无法在合并表单中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13872746/

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