2017-04-23 317 views
1

這是我的代碼,我有第二個到最後一行,我定義$ params變量的未定義索引通知。這是我到uploadImage電話,我通過$從另一個文件PARAMS值,未定義的索引爲postimg和postid數組的

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

我試過,如果postimg和帖子ID設置檢查,如果他們是空的,但如果正在執行沒有在這些聲明。

<?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); 


     } 

    } 

?> 
+0

你有一個函數調用__4__參數,但只有__3__在函數定義中。 –

回答

2

接近在Image::uploadImage調用查看:

Image::uploadImage(
    // $formname argument 
    'postimg', 
    // $query argument 
    "UPDATE dry_posts SET postimg = :postimg WHERE id = :postid", 
    // $params argument 
    array(':postid' => $postid), 
    // Wait what is this? 
    array(':postimg' => $postimg) 
); 

所以,你的PARAMS應該一個陣列傳遞:

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

接下來,你不必在'postid'關鍵$params。您有':postid'

所以,無論是線

$params = array(':postid' => $params['postid'], ':postimg' => $params['postimg']); 

必須是:

// add ':' prefix 
$params = array(':postid' => $params[':postid'], ':postimg' => $params[':postimg']); 

或者傳遞給函數的參數應該是:

// $params argument, no `:` prefixes 
array(
    'postid' => $postid, 
    'postimg' => $postimg 
) 
+0

謝謝,但現在我得到了這個通知,注意:數組到字符串轉換 – Bubba

+0

我應該自己轉換嗎? – Bubba

+0

這意味着某處您嘗試打印數組的值。 –