这是我的脚本:-
if (isset($_POST['confirm_close_complaint_submit']))
{
if($_FILES['complaint_file']['tmp_name'] == "none")
{
header('Location: complaint-register.php?FileSizeError=1');
exit();
}
$filename = basename($_FILES['complaint_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext != "jpg") && ($_FILES["uploaded_file"]["type"] != "image/jpeg"))
{
header('Location: complaint-register.php?FileTypeError=1');
exit();
}
else
{
$destination = '../../stored/complaint-files/'.$_POST['confirm_close_complaint'].$_FILES['complaint_file']['name'];
$temp_file = $_FILES['complaint_file']['temp_name'];
move_uploaded_file($temp_file, $destination);
$insertSQL = sprintf("UPDATE complaints SET complaint_status='CLOSED', complaint_solved_date=NOW(), complaint_remark=%s WHERE complaint_number=%s",
GetSQLValueString($_POST['complaint_remark'], "text"),
GetSQLValueString($_POST['confirm_close_complaint'], "text"));
$Result1 = mysql_query($insertSQL, $dacreint) or die(mysql_error());
header('Location: complaint-register.php?ComplaintClose=Successful');
exit();
}
}
此脚本执行 mysql 插入但不上传文件。它向我显示了成功的消息。
这是我的表格:-
<form enctype="multipart/form-data" method="post" action="complaint-register.php">
<table border="0">
<tr>
<td>Remark</td>
<td><textarea name="complaint_remark" class="textarea"></textarea></td>
</tr>
<tr>
<td>Complaint File</td>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input name="complaint_file" type="file" size="100" /></td>
</tr>
</table>
<div class="clear"></div>
<input name="confirm_close_complaint" type="hidden" value="'.$close_complaint.'" />
<input name="confirm_close_complaint_submit" type="submit" class="Button" style="float:left;" value="Yes" />
<input name="" type="button" class="Button" style="float:left;" onClick="javascript:history.go(-1)" value="No" />
</form>
我定义路径的方式是否正确,即$destination = '../../stored/complaint-files/'.$_POST['confirm_close_complaint'].$_FILES['complaint_file']['name'];
?
并且做这个条件是可以的$temp_file = $_FILES['complaint_file']['tmp_name'];