通过jquery $ .post()和php发送原始多部分数据 [英] Sending raw multipart data through jquery $.post() and php

查看:223
本文介绍了通过jquery $ .post()和php发送原始多部分数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要发送原始的多部分数据与php POST但没有html形式... im启动过程与jquery $ .post()(目的是更改twitter帐户的背景)。

i need to send raw multipart data with a php POST but without an html form... im starting the process with jquery $.post() instead (the objective is to change a twitter account's background).

我如何实现呢?这是我目前的(仍然不完整的)代码:

How can i achieve that? This is my current (and still incomplete) code:

1)在此隐藏的输入字段中插入图像文件名:

1) Image filename is inserted in this hidden input field:

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

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

2) when clicking on the submit button, a javascript function is triggered... and it calls:

$.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. im使用Abraham Williams的twitteroauth库0.2

  1. all the background files are inside the /www/uploads local directory.
  2. im using Abraham Williams' twitteroauth library 0.2

底线,在第三步,我需要在 中发送 $ param ['image']

Bottom line, in step three i need to send $param['image'] in raw multipart data to the $connection object (twitter library).

任何想法?

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

推荐答案

是的,我现在看到他建立post字段数组到查询字符串,这意味着你必须手动设置内容类型,并且 @ 键在图像因为它只适用于数组参数。更重要的是,我没有看到一个修改标头而不会破坏库或扩展它并替换某些函数的方法。

Yeah i see now that hes building the post fields array into a query string which means you have to manually set the content type and that the @ key in the image fields wont do its magic since that only works with an array argument. More importantly i dont see a way to modify the headers without hacking the library or extending it and replacing certain functions.

将尝试将 @ 前面的图像参数的文件路径:

I would try would be prepending @ to the file path of the image param like:

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

这是使用cURL的方便方法,它看起来像libray基本上使用cURL发出请求,这样应该可以正常工作。

That is the convenient way to do it with cURL, and it looks like the libray basically uses cURL to make the request, so that should work.

这篇关于通过jquery $ .post()和php发送原始多部分数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆