【发布时间】:2017-09-20 09:16:49
【问题描述】:
这是我的代码,我在定义 $params 变量的倒数第二行有未定义的索引通知。这是我对 uploadImage 的调用,我从另一个文件传递 $params 值,
Image::uploadImage('postimg', "UPDATE dry_posts SET postimg = :postimg WHERE id = :postid", array(':postid' => $postid),array(':postimg' => $postimg));
我尝试检查是否设置了 postimg 和 postid 以及它们是否为空,但在这些 if 语句中没有任何内容正在执行。
<?php
include_once("connect.php");
class Image
{
public static function uploadImage($formname,$query,$params)
{
$image = "";
$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!');
}
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'https://api.imgur.com/3/image&mpaction=convert format=flv');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'beautify');
$response = curl_exec($curl_handle);
curl_close($curl_handle);
echo 'hell0';
$response = json_decode($response);
$params = array(':postid' => $params['postid'], ':postimg' => $params['postimg']);
connect::query($query,$params);
}
}
?>
【问题讨论】:
-
函数调用中有 4 个参数,但函数定义中只有 3 个参数。
标签: php arrays image undefined-index