0

我需要使用 php POST 发送原始多部分数据,但没有 html 表单...我使用 jquery $.post() 开始该过程(目标是更改 Twitter 帐户的背景)。

我怎样才能做到这一点?这是我当前(但仍然不完整)的代码:

1)图像文件名被插入到这个隐藏的输入字段中:

<input type="hidden" id="profile_background_image_url" value="oats.jpg" />

2)当点击提交按钮时,一个javascript函数被触发......它调用:

$.post('helper.php',{
 profile_background_image_url:$('#profile_background_image_url').val()
});

3) helper.php

$param = array();
$param['image'] = '/www/uploads/'.$_POST['profile_use_background_image'];
$status = $connection->post('account/update_profile_background_image',$param);

备注

  1. 所有背景文件都在/www/uploads本地目录中。
  2. 我正在使用 Abraham Williams 的 twitteroauth 库 0.2

底线,在第三步中,我需要将原始多部分数据中的$param['image']发送到$connection对象(twitter 库)。

有任何想法吗?

一些参考资料:http ://dev.twitter.com/doc/post/account/update_profile_background_image

4

2 回答 2

1

是的,我现在看到他将帖子字段数组构建为查询字符串,这意味着您必须手动设置内容类型,并且字段中的@image不会发挥它的魔力,因为它仅适用于数组参数。更重要的是,我看不到在不破解库或扩展它并替换某些功能的情况下修改标题的方法。


我会尝试@在参数的文件路径之前添加image

$param['image'] = '@/www/uploads/'.$_POST['profile_use_background_image'];

这是使用 cURL 进行操作的便捷方式,看起来 libray 基本上使用 cURL 来发出请求,所以应该可以。

于 2010-12-07T02:47:04.010 回答
0

解决了!

curl_setopt($ci, CURLOPT_POST, TRUE);
        if(is_array($files)){
          $post_file_array = array();
          foreach($files as $key=>$value){
             $post_file_array[$key] = "@{$value}";
          }
          curl_setopt($ci, CURLOPT_POSTFIELDS, $post_file_array);
          if (!empty($postfields)) {
            $url = "{$url}?{$postfields}";
          }
        }
        else if (!empty($postfields)) {
          curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
        }
于 2010-12-07T20:51:32.597 回答