【发布时间】:2017-04-18 19:46:50
【问题描述】:
在使用file_get_contents() 函数定义$image 变量后,我收到了这个警告:
警告:file_get_contents():文件名不能为空
即使我通过此方法调用将值传递给$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(':postid'=>$postid);
$params = array(':postid' => $params['postid'], ':postimg' => $params['postimg']);
connect::query($query,$params);
}
}
?>
【问题讨论】:
-
但是您在这里取消设置“$formname”? $formname = "";所以在方法调用中传入也没关系,永远是空的。
-
哇,我想我只是需要一双新鲜的眼睛
-
谢谢,刚刚将其添加为官方答案。如果您将其标记为解决方案,将不胜感激。