首页 > 解决方案 > 表单上传如何显示?当我运行这个文件时

问题描述

我有一个如下的 php 脚本

<?php
if($_FILES['img']['type'] != "image/gif") {
    echo "<center><br>param name: img<br>directory file /challenge/ex";
    exit;
}
$uploaddir = 'ex/';
$uploadfile = $uploaddir . basename($_FILES['img']['name']);
if (move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "File uploading failed.\n";
}
?>
<center>
<br><br>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" size="20" name="img" />
        <input type="submit" name="upload" value="Upload" />
    </form>

但是,当我运行这个文件时,表单上传和按钮无法显示

标签: phpupload

解决方案


这主要发生在出现 php 错误时,请尝试在第二行之前添加这三行:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

所以它将是:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if($_FILES['img']['type'] != "image/gif") {
    echo "<center><br>param name: img<br>directory file /challenge/ex";
    exit;
}
$uploaddir = 'ex/';
$uploadfile = $uploaddir . basename($_FILES['img']['name']);
if (move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "File uploading failed.\n";
}
?>
<center>
<br><br>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" size="20" name="img" />
        <input type="submit" name="upload" value="Upload" />
    </form>

希望会出现一些错误,以便我们修复它。


推荐阅读