无法上传文件

时间:2012-04-10 11:58:49

标签: php file-upload

这是我的剧本: -

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

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:1)

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