从上传的文件中读取值并将其发送到URL地址

时间:2015-02-23 07:51:16

标签: php json

<? 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>";
}

$line = fgets($f_open);
echo $line;
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=";
$furl ="$url"."$line";
echo "$furl";
$ch = curl_init("$furl");
$fp = fopen("example4.txt","w");

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


echo $json['results'][0]['address_components'][0]['types'][0];
echo $json['results'][0]['address_components'][0]['types'][1];

$data=json_decode($jsondata); 
$address=$data->results[0]->address_components; 
?>

bove提到的程序,

我正在尝试从上传的文件中逐行检索值,并将检索值与url连接,

但是我收到了错误消息..

  

注意:尝试获取非对象的属性   第50行的C:\ xampp \ htdocs \ phpprog \ upload_file_add.php ......

我的描述错误在哪里......

2 个答案:

答案 0 :(得分:0)

我猜你需要在使用json_decode之前检查你的$ jsondata变量是否有效。您可能在$ data中收到null,因此当您尝试访问其属性时,它不再是对象。 在json_decode($ jsondata)之后使用var_dump($ data)来验证你是否正在接收你期望的内容。

答案 1 :(得分:0)

您向我们提供的代码中包含我们不知道其来源的变量,例如$f_open$json。如果不使用fgets()打开文件,则无法使用fopen()

$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);
echo $line;
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=";
$furl ="$url"."$line";
echo "$furl";

阅读包含reading_files_with_PHP的文字文件 上面的代码显示

  

reading_files_with_PHP
  http://maps.googleapis.com/maps/api/geocode/json?address=reading_files_with_PHP