[英]PHP Form File Upload doesnt work
I want to upload Images or MP4 Videos.我想上传图片或 MP4 视频。
I have this Code:我有这个代码:
<form role="form" action="addad.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="file">Image or MP4 Please</label>
<input type="file" id="FileInput" name="file" required>
<div id="responses"></div>
</div>
</form>
if(!isset($_FILES['file'])){
echo "No File";
exit;
}
$uploaddir = '/var/www/xxxxxx.com/control/uploads/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
echo $uploadfile;
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
echo "Image succesfully uploaded.";
} else {
echo "Image uploading failed.";
exit;
}
But its already crashed in isset with Message "No File", when i try to upload...但是当我尝试上传时,它已经因消息“无文件”而在 isset 中崩溃了...
Any Ideas?有任何想法吗? Already checked PHP User and changed folders to www-data Also tried permissions 777 but nothing works.已经检查了 PHP 用户并将文件夹更改为 www-data 还尝试了权限 777 但没有任何效果。
Everytime it looks like, he dont get any file informations or dont see the file.每次看起来,他都没有得到任何文件信息或没有看到文件。 All other fields in my form works.我表单中的所有其他字段都有效。 If i dont make exit;如果我不退出; it write all other fields to database.它将所有其他字段写入数据库。
Make sure your "submit" input/button is inside the form确保您的“提交”输入/按钮在表单内
<form role="form" action="addad.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="file">Image or MP4 Please</label>
<input type="file" id="FileInput" name="file" required>
<div id="responses"></div>
</div>
<input type="submit" value="Submit File"/>
</form>
In the "addad.php" file, var_dump($_FILES)
before the "if(!isset())" part and check if your data is beeing shown, something like this:在“addad.php”文件中,“if(!isset())”部分之前的var_dump($_FILES)
并检查您的数据是否显示,如下所示:
Your Condition is Wrong .你的条件是错误的。 Use:用:
if(isset($_FILES['file'])){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.