gpt4 book ai didi

php - 移动文件并将文件数据保存为空白时出现问题

转载 作者:行者123 更新时间:2023-11-30 01:13:35 24 4
gpt4 key购买 nike

我这里有一些问题..

我使用index.php上的上传,并使用jquery(ajax)将任何信息保存到mysql。我有3个文件index.php、savedata.php、jsSave.js

但是当我使用 savedata.php 中的 $_REQUEST 文件并且结果在 mysql 表中也是空白响应时,我替换 $_REQUEST 并使用 $_FILES 并得到相同的结果。

我已经尝试和使用的是如下代码......

索引.php

        <form class="myform" action="<?php $_SERVER['PHP_SELF'];?>" method="POST" name="myform" id="myform" enctype="multipart/form-data" style="width:350px;">

<li>
<label>Item Picture</label>
<div class="fileUpload btn btn-primary">
<span>Choose Image..</span>
<input type="file" name="cItemPicture" class="cItemPicture" id="cItemPicture"/>
</div>
<input type="hidden" name="cPic" id="cPic"/>
</li>

<li>
<img border="0" src="images/loading_transparent.gif" width="20" height="20" id="imgLoad">
&nbsp<button class="button_blue" id="butTblSave" type="submit" style="width: 81px; height: 33px">SAVE</button>
</li>

对于 savedata.php 文件脚本是

    <?php 
if($_REQUEST)
{
***$cItemPicture=$_FILES["cItemPicture"]["name"];***

$sql="INSERT INTO tblData(item_image) VALUES ('$cItemPicture')";

$result=mysql_query($sql) or die('Cannot Connect To SQL Server, Please contact your administrator');
move_uploaded_file($_FILES["cItemPicture"]["tmp_name"],
"upload/" . $_FILES["cItemPicture"]["name"]);
}
?>

最后一个使用 jQuery 文件作为 AJAX 工作的文件是 jsSave.js

    $(document).ready(function() {
$('#imgLoad').hide();
$('#msgConfirm').hide();
$('#tblAvailabilityResult').hide();
});

$(function() {
$("#butTblSave").click(function() {
$.ajax({
type: 'POST',
url: 'saveData.php',
data: $('form').serialize(),

beforeSend: function() {
$("imgLoad").show();
},

complete: function() {
$("imgLoad").hide();
},

cache: false,

success: function () {

$("#cItemPicture").val('');

$('#imgLoad').hide();
$('#butTblSave').attr("disabled", false);

$('#msgConfirm').fadeIn(500).delay(5000).fadeOut(1000);
$("#msgConfirm").html(' Add New Item Success.');

}

});
return false;
}

});
});

我错过了什么吗?当按下“保存”按钮时,ajax 响应为空白,并将数据保存到 mysql item_image 中也是空白,也没有文件移动到上传文件夹中。

对这个问题有什么想法吗?非常感谢。

谢谢

最佳答案

尝试阻止表单的默认提交。因为表单正在提交给SELF(index.php)

$("#butTblSave").click(function(event) { 
event.preventDefault();
...

关于php - 移动文件并将文件数据保存为空白时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19267053/

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