更改服务器后的表单上载错误

时间:2013-09-20 15:09:34

标签: php

我有一个工作上传表格,然后最近为我已经在预先存在的计划上工作的网站购买了一个专门的托管计划(GoDaddy - 是的,我知道的邪恶)。但是,尽管文件结构与完全写入权限完全相同,但上载不再有效,但数据库已更新,尽管只有在存在图像时才更新数据库。我不明白为什么不再上传该文件:

if ($state == "post") {
    $title = $_POST['title'];
$body = $_POST['body'];
if(! empty($_FILES['file']['name'][file])) {
    $allowed_extensions = array("jpeg", "jpg", "png");
    $upload_extension = end(explode(".", $_FILES['file']['name'][file]));
    if (in_array($upload_extension, $allowed_extensions)) {
    $loop = true;
    $im = null;
    while ($loop) {
        $rand_count = 0;
        while ($rand_count != 10) {
            $rand = rand(1,9);
        $im = $im . $rand;
        $rand_count++;
        }
        $image = $im.".".$upload_extension;
        if (!file_exists("images/posts/" . $image)) {
            list($width, $height) = getimagesize($_FILES['file']['tmp_name'][file]);
        if ($height > $width)
                        $width_n = 160; $height_n = $height/$width*$width_n;
        else
            $height_n = 160; $width_n = $width/$height*$height_n;

            $tmp_image = imagecreatetruecolor($width_n, $height_n);
        if (($upload_extension == "jpeg") || ($upload_extension == "jpg"))
                        $src = imagecreatefromjpeg($_FILES['file']['tmp_name'][file]);
        elseif ($upload_extension == "png")
            $src = imagecreatefrompng($_FILES['file']['tmp_name'][file]);
        //tmp_upload 
        imagecopyresampled($tmp_image, $src, 0, 0, 0, 0, $width_n, $height_n, $width, $height);
        $path = "images/posts/".$image;
        imagejpeg($tmp_image, $path, 100);
                    $stmt = "INSERT INTO posts (post_title, post_body, post_image) VALUES ('$title', '$body', '$image')";
        if (!mysqli_query($con, $stmt))
                        die('Error: ' . mysqli_error($con));
            $loop = false;
        header('Location: index.php');
        }
    }
    }
}
}

images/posts存在于新服务器上。

1 个答案:

答案 0 :(得分:0)

您以完全错误的方式使用$_FILES。在您使用它的每个实例中,您需要删除尾随[file]

$_FILES['file']['tmp_name'][file]

变为

$_FILES['file']['tmp_name']