PHP上传程序的问题

PHP上传程序的问题,php,forms,Php,Forms,我有一个简单的表单,允许用户存储一些HTML代码、标题和图像。表单将数据发送到PHP,PHP应该存储图像和其他不相关的内容。图片没有上传,但我没有收到任何错误。这个工具的存在只是为了给我一种添加内容的方式,其他人无法访问它,所以我还没有做任何输入检查 HTML: PHP在读取错误代码之前已重定向。我使用的测试映像不正确,重定向使我看不到正确的错误代码。这个问题通过移除 header('Location: /../index.html'); 并使用不同的图像。显示的是哪条消息?无,这是主要问题。

我有一个简单的表单,允许用户存储一些HTML代码、标题和图像。表单将数据发送到PHP,PHP应该存储图像和其他不相关的内容。图片没有上传,但我没有收到任何错误。这个工具的存在只是为了给我一种添加内容的方式,其他人无法访问它,所以我还没有做任何输入检查

HTML:


PHP在读取错误代码之前已重定向。我使用的测试映像不正确,重定向使我看不到正确的错误代码。这个问题通过移除

header('Location: /../index.html');

并使用不同的图像。

显示的是哪条消息?无,这是主要问题。检查错误日志检查日志,除了一些无关的内容外,没有任何问题。但是我发现了问题,我只是在装傻。文件中的另一行阻止错误显示-u-,这只是我使用的测试文件中的一个错误。很抱歉浪费您的时间。您发布的任何代码中都没有这一行。下次请发布完整代码,以免浪费任何人的时间。我明白,是否应该始终发布完整代码?还是有例外?谢谢你的链接,我通读了它,下次会更好地遵循指南。
#Image code
$target_dir = "../BlogPosts/post_images/";
$target_file = $target_dir . basename($_FILES["img_upload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if (isset($_POST["submit"])) {
    $check = getimagesize($_FILES["img_upload"]["tmp_name"]);
    if ($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["img_upload"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["img_upload"]["tmp_name"], $target_file)) {
        echo "The file " . basename($_FILES["img_upload"]["name"]) . " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
header('Location: /../index.html');