2017-04-23 6 views
1

私のコードは、$ params変数を定義する2番目から最後の行に未定義のインデックス通知があります。ここで私は$は別のファイルから値をparamsは渡しuploadImageに私の呼び出し、postimgとpostid配列の未定義インデックス

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

は、文が実行されていた場合postimgとpostidが設定されていないと、彼らは空だった場合は、しかし、それらの中には何もされている場合、私はチェックしてみたです。近いImage::uploadImageコールで

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

ルック:だから、あなたのparamsは配列として渡す必要があり

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

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

これは配列の値を出力しようとしているところです。 –

関連する問題