0

这是我的脚本:-

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'];

4

2 回答 2

4


$_FILES['complaint_file']['temp_name'];
应该

$_FILES['complaint_file']['tmp_name'];
如果上传,请在其中添加您的更新声明,例如


if(move_uploaded_file($temp_file, $destination)) {
  //your update statement here
}
else {
  //error
}

尝试检查您的目标路径是否有效。设置错误报告:


ini_set('display_errors',1);
error_reporting(E_ALL);
于 2012-04-10T12:00:47.870 回答
1

尝试处理来自 move_uploaded_file 的错误。您不应显示该呼叫失败的“成功”消息。

于 2012-04-10T12:01:04.887 回答