php - 表单上传如何显示?当我运行这个文件时
问题描述
我有一个如下的 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>
但是,当我运行这个文件时,表单上传和按钮无法显示
解决方案
这主要发生在出现 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>
希望会出现一些错误,以便我们修复它。
推荐阅读
- javascript - 检查失败的 HTTP 请求
- c# - AutoCAD C# 版本 .dwl 文件
- sql - Golang 中的多租户
- python - Python - PyQt:QThread 完成后继续
- php - 带有嵌套路由的 PHP REST API
- excel - 日期之间的 Sumproduct 与跨列的附加条件
- jenkins - 当特定 JIRA 项目下的所有问题的状态更改为“IN PROGRESS”状态时触发 Jenkins 构建
- css - SVG 在多个图层上的悬停状态,不仅是顶层
- selenium - 如何使用 Jmeter/任何其他工具从所有请求中捕获一些事件请求
- python - 如何在 Celery 中异步接收已处理的消息?