我正在使用 php/html5 并且正在尝试上传文件,但$_FILES['picture']
似乎从未包含任何内容。我浏览了很多帖子并寻找常见的修复方法,但它们似乎都不起作用,首先是代码;
形式;
<form enctype="multipart/form-data" action="decodeQR.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000000" />
<input type="file" name="picture" id="picture" value="picture" accept="picture/*" capture>
<input type="submit" value="Upload">
</form>
解码QR.php;
<?php
include 'header.php';
$upload_status = FALSE;
if(isset($_FILES['picture']))
{
echo 'picture set <br>';
}
else
{
echo 'picture not set <br>';
}
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
if (isset($_FILES['picture']) && file_exists($_FILES['picture']['tmp_name']))
{
$image = $_FILES['picture']['tmp_name'];
//~ Check if image is an image
if (@getimagesize($image))
{
$upload_status = TRUE;
//~ from here you can use yours image as $_FILES['picture']['name'], for example to copy it
move_uploaded_file($image, realpath(dirname(__FILE__)).'/images/'.$_FILES['picture']['name']);
//~ Also be noticed that the image curently is in OS tmp folder and if you dont copy it, it will be deleted after script execution.
}
}
if ($upload_status)
{
echo 'Image successfully uploaded. <br> <img src="images/'.$_FILES['picture']['name'].'">';
}
else
{
echo 'nope.jpg';
}
?>
输出总是;
图片未设置
不.jpg
这意味着$_Files['picture']
未设置,并且文件数组中没有错误。
正如您从上面的代码中看到的那样,我已经尝试了以下修复;
- 添加了表单 enctype 的标记;
enctype="multipart/form-data
" - 添加了隐藏
MAX_FILE_SIZE
属性 - 未显示在代码中,我尝试在文件标签中添加 size='30000000'
- 我在设置和获取文件时检查了值/名称是否相同
- 我还检查了 php.ini 以确保允许 file_upload
我可能会错过什么?
编辑; 我已经在我的桌面和移动浏览器上尝试过这个。