我正在使用easy ui并制作一个与mysql和php连接的文件上传器
这是我插入新数据的代码
<?php
$desc = $_REQUEST['resultDesc'];
//------------------ Check file for error message ----------------
if($_FILES["resultFile"]["error"] <= 0)
{
//------------------ Check wether file exists -----------------
if (!(file_exists("results/" . $_FILES["resultFile"]["name"])))
{
//----------- Upload File ----------------------------------
move_uploaded_file($_FILES["resultFile"]["tmp_name"],
"results/" . $_FILES["resultFile"]["name"]);
include 'Connection.php';
//--------------- Todays Date ----------------------------
$today = date("Y-m-d");
$file = $_FILES["resultFile"]["name"];
$sql = "insert into results(id,date,description,filename)
values(NULL,'$today','$desc','$file')";
$result = @mysql_query($sql);
if ($result)
{
echo json_encode(array('success'=>true));
}
else
{
echo json_encode(array('msg'=>'Some errors occured.'));
}
//--------------------- Close COnnection ------------------
mysql_close($connection);
}
}
else
echo json_encode(array('msg'=>'Some errors occured.'));
?>
在用户端我有这个代码
<div class="fitem">
<label>Description</label>
<textarea name="resultDesc" style="width:300px;height:100px;resize:none" class="easyui-validatebox" required="true"></textarea>
<label>Result File</label>
<input type="file" name="resultFile" size = "30px;" class="easyui-validatebox" required="true">
</div>
以上代码无效。请帮忙。文件上传不包含在easy ui中,我正在制作自定义文件。
答案 0 :(得分:0)
尝试替换
$sql = "insert into results(id,date,description,filename)
values(NULL,'$today','$desc','$file')";
用这个:
$sql = "insert into `results`(`id`,`date`,`description`,`filename`)
values(NULL,'$today','$desc','$file')";
使用反引号转义字段名称。
答案 1 :(得分:0)
如果javascript正在调用此php文件,请尝试。 {window.location =“您的文件名”; }。
尝试将所有变量回显为 {$ _REQUEST ['resultDesc'],$ _FILES [“resultFile”] [“name”]}