2011-02-12 99 views
1

我有一个简单的iPhone应用程序,我正在上传图片到Facebook。为此,我必须在服务器上放置多个文件。从此,它将转到Facebook。我有我的PHP代码下面,将做服务器端。数组中的变量(PHP)?

问题是,当我在数组中放置一个变量时,它不起作用。我尝试了所有不同的选项,但它并不适合我。

任何帮助表示赞赏!谢谢。

$args = array(
'message' => 'Photo from the ******** iPhone Application.', 
'$short_url' => '$short_url' 
); 

$url = 'https://graph.facebook.com/'.$album_id.'/photos?access_token='.$get_facebook_token; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $args); 
$data = curl_exec($ch); 
//returns the photo id 
print_r(json_decode($data,true)); 
+0

好了,所有的报价看这里很好,你怎么得到的结果,而你到底在期待? – JakeSteam

+3

这是什么? ''$ short_url'=>'@ $ short_url'' |试试''short_url'=> $ short_url'。单引号'''',不要内插。 – Orbling

+0

你是对的。 @把我扔在那里。 – JakeSteam

回答

2

您正在使用单引号是你应该直接使用变量或双引号,因此变量被插值:

$args = array(
    ..., 
    "short_url" => "@$short_url", 
); 

或者类似的东西。取决于所假设的表单字段名称。并且“@ $ var”probaby导致用curl文件上传。

1

围绕可变卸下''太它不会作为字符串进行处理。

$args = array(
'message' => 'Photo from the ******** iPhone Application.', 
'short_url' => $short_url 
); 
+0

你认为这是他需要的吗? – zerkms

0

你可能需要

"short_url" => $short_url