为什么我的变量在传递值时被视为 null?

Why is my variable being treated like it's null when it's being passed a value?

我在使用 file_get_contents() 函数定义 $image 变量后收到此警告:

Warning: file_get_contents(): Filename cannot be empty

即使我通过此方法调用将值传递给 $formname

Image::uploadImage('postimg', "UPDATE dry_posts SET postimg = :postimg WHERE id = :postid", array(':postid' => $postid),array(':postimg' => $postimg));

$postimg是表单中的一个文件变量。我试过检查文件是否存在,这解决了错误,但当然没有执行任何操作。好像每次用file_get_contents()都不喜欢,怎么改?

<?php
include_once("connect.php");

    class Image
    {
        public static function uploadImage($formname,$query,$params)
        {

            $formname = "";
            $response = "";
            $image = "";
            echo 'hello';
            //if(file_exists($formname))
            //{
                echo 'hello';
                $image = base64_encode(file_get_contents($_FILES[$formname]['tmp_name']));
            //}
            $options = array('http'=>array(
                'method'=>"POST",
                'header'=>"Authorization: Bearer access code here\n".
                "Content-Type: application/x-www-form-urlencoded",
                'content'=>$image
            ));

            $context = stream_context_create($options);
            $imgurURL = "https://api.imgur.com/3/image";
            if ($_FILES[$formname]['size'] > 10240000) {
                die('Image too big, must be 10MB or less!');
            }

            //if(file_exists($formname))
            //{
                echo 'hell0';
                $response = file_get_contents($imgurURL, false, $context);

            //}
            $response = json_decode($response);

            //from 
            //$prearams = array($formname=>$response->data->link);
            //$params = $preparams + $params;

            //from changes 
            //$params=array(':post‌​id'=>$postid);
            $params = array(':postid' => $params['postid'], ':postimg' => $params['postimg']);
            connect::query($query,$params);


        }

    }


?>

您要在此处取消设置“$formname”吗? $表单名 = "";所以如果你在方法调用中传递它也没关系,它永远是空的