本文介绍了图片上传不适用于php7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用nginx作为服务器和php7.我遵循了一些指示,并且一定做错了什么.
I use nginx as server and php7. I followed some instructions and must have made something wrong.
表格:
<div class="collapse" id="upload_avatar">
<div class="card card-body">
<form enctype="multipart/form-data" action="" method="post">
<p class="text-left">Upload Avatar:</p>
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<input name="image" type="file" /><br>
<button class="form-control mr-sm-2 btn btn-outline-success my-2 my-sm-0" type="submit" name="avatar_upload" aria-controls="collapse_upload_avatar">
Upload
</button>
</form>
</div>
</div>
php部分:
if(isset($_POST["avatar_upload"])){
$verifyimg = getimagesize($_FILES['image']['tmp_name']);
if($verifyimg['mime'] != 'image/png') {
echo "Only PNG images are allowed!";
exit;
}
$uploaddir = '/members/3/';
$uploadfile = $uploaddir . basename($_FILES['image']['name']);
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.<br>";
} else {
echo "Possible file upload attack!<br>";
}
echo '<pre>';
echo 'info:';
print_r($_FILES);
print "</pre>";
}
它打印出来:
Possible file upload attack!
info:Array
(
[image] => Array
(
[name] => Selection_001.png
[type] => image/png
[tmp_name] => /tmp/phpGpp3rB
[error] => 0
[size] => 299338
)
)
没有/tmp/php* file
/members/3/
目录中没有文件
/members
和/members/3
是否缺少nginx设置?
Is a nginx setting missing???
推荐答案
在您的成员目录中删除/.
Remove / in your members directory.
$ uploaddir ='members/3/';
$uploaddir = 'members/3/';
这篇关于图片上传不适用于php7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!