2015-02-23 71 views
-1
if(isset($_POST["submit"])) 
    { 
    $f_name = $_FILES["filetoupload"]["name"]; 
    $f_tmp = $_FILES["filetoupload"]["tmp_name"]; 
    $store = "uploads/".$f_name; 
    if(move_uploaded_file($f_tmp,$store)) 
     { 
      echo "file uploaded successfully";`` 
      echo"<br>"; 
     } 
     $f_open = fopen($store,"r"); 
     $line = fgets($f_open); 
    $url = "http://maps.googleapis.com/maps/api/geocode/json?address="; 
    $furl ="$url"."$line"; 
    echo "$furl"; 
     $ch = curl_init(); 
     $fp = fopen("example4.txt","w"); 
     curl_setopt($ch, CURLOPT_URL, $furl); 
     curl_setopt($ch, CURLOPT_PROXY, '10.10.80.11:3128'); 
     curl_setopt($ch, CURLOPT_FILE, $fp); 
     curl_setopt($ch, CURLOPT_HEADER, 0); 

     curl_exec($ch); 
     curl_close($ch); 
     fclose($fp); 

JSON DECOD無法提取文本文件JSON解碼不獲取URL

  $jsondata = file_get_contents('example4.txt',true); 
     $data=json_decode($jsondata,true); 
     echo "$data"; 
     (line 50) $address=$data->results[0]->address_components; 
     echo "$address"; 

}
這裏JSON解碼似乎沒有工作,因爲它不是借陣列 ,也沒有URL ISN 「T通過curl.and errorr passsing是注意:試圖讓非對象的屬性在C:\ XAMPP \ htdocs中\ phpprog \ upload_file_add.php上線50 ...任何幫助將是 欣賞

+0

那麼什麼是文件的內容'範例4 .txt'? – 2015-02-24 10:57:28

回答

0

假設的example4.txt的內容從谷歌API返回一個有效的JSON結果:你的數據主要是數組,而不是對象,所以你需要按如下方式訪問:

$address=$data['results'][0]['address_components']; 
print_r($address); 
$long_name=$address[0]['long_name']; 
echo $long_name; 
+0

thanx很多!但先生Hans Z.實際上JSON結果不是由example4.txt中的curl返回的。我該如何解決這個問題 – 2015-02-25 06:38:49