I've been getting this warning after defining the $image
variable using the file_get_contents()
function:
Warning: file_get_contents(): Filename cannot be empty
Even though I passed a value to $formname
with this method call :
Image::uploadImage('postimg', "UPDATE dry_posts SET postimg = :postimg WHERE id = :postid", array(':postid' => $postid),array(':postimg' => $postimg));
$postimg
is a file variable in a form. I've tried checking if the file exists, which solved the error but of course nothing was being executed. It seems to not like it whenever I use file_get_contents()
, how do I turn this around?
<?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);
}
}
?>
You are unsetting "$formname" here? $formname = ""; So doesn't matter if you pass it in the method call, it will always be empty