图片上传不适用于php7 [英] Image upload not working for me with php7

查看:206
本文介绍了图片上传不适用于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/error.log显示: PHP消息:PHP警告:move_uploaded_file(/members/3/Selection_001.png):无法打开流:第197行上没有此类文件或目录... PHP消息:PHP警告:move_uploaded_file():无法将'/tmp/phpGpp3rB'移动到'/members/3/Selection_001.png'

nginx/error.log shows: PHP message: PHP Warning: move_uploaded_file(/members/3/Selection_001.png): failed to open stream: No such file or directory ... on line 197 PHP message: PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpGpp3rB' to '/members/3/Selection_001.png'

是否缺少nginx设置?

Is a nginx setting missing???

推荐答案

在您的成员目录中删除/.

Remove / in your members directory.

$ uploaddir ='members/3/';

$uploaddir = 'members/3/';

这篇关于图片上传不适用于php7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆