PHP和卷曲,深阵列发布 [英] Posting with PHP and Curl, deep array

查看:97
本文介绍了PHP和卷曲,深阵列发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过卷曲后,我一直在使用同样的code一遍又一遍,没有问题,但现在我需要能够使用上岗数组(我不知道有一个适当的词是什么?)。

I'm trying to post via curl, I've been using the same code over and over again with no problem but now I need to be able to use an array for posts (i'm not sure if there's a proper term for that?).

我要澄清的是,它是专门的文件我试图张贴,但我不能把它与一个字符串,要么是工作所以我不认为它太有做到这一点。

I should clarify that it's specifically a file i'm trying to post, but I can't get it working with a string either so I don't think it's too do with that.

这是absouletly罚款:

This is absouletly fine:


$uploadData = array();
$uploadData['uploads'] = "@".$file;
$uploadData['iagree'] = 'on';

这似乎并没有工作:


$uploadData = array();
$uploadData['uploads'][0] = "@".$file;
$uploadData['iagree'] = 'on';

在第二个例子中我试图复制的属性名称输入=上传[]

In the second example i'm trying to replicate an input with the attribute name="uploads[]"

显然,我试图卷曲外部网站,但如果我尝试我自己的服务器上卷曲的网页,这样我可以看到东西被发送到了什么,我可以看到上传的阵列被转换为字符串:

Obviously i'm trying to curl an external site, but if I experiment curling a page on my own server so that I can see what's being sent, I can see that the uploads array is being converted to a string:


print_r($_POST);
print_r($_FILES);

返回:


Array
(
    [uploads] => Array
    [iagree] => on
)

Array
(
)

这是我的全部卷曲:


    $uploadData = array();
    $uploadData['uploads'][] = "@".$file;
    $uploadData['iagree'] = 'on';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $theLink);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $uploadData);
    $upload_response = curl_exec($ch);
    curl_close($ch);

我试图让尽可能多的信息越好,但如果我错过了什么随便问,我会提供更多的。

I've tried to give as much information as possible, but if i've missed something feel free to ask and i'll provide more.

除此之外,没有任何人有任何建议或解决方案?

Other than that, does anyone have any suggestions or solutions?

推荐答案

$ uploadData ['上传[]'] =@$文件; 并将其传递作为数组应该工作,只要记住,你需要的文件的绝对路径。

$uploadData['uploads[]'] = "@".$file; and passing it as an array should work, just keep in mind you need the absolute path to the file.

有在'简单'的HTTP(多部分/格式数据或应用程序/ x-WWW的形式urlen codeD)没有机制来发送阵列。然而,PHP间$ P $点的 [&安培; ] 键 - 值对特殊字符。 PHP是的单独的在AFAIK,它不是一个断点续传机制,它的输入PHP只是解析做,为的是将的在值的名称_ 。卷曲是一个第三方包,其中从PHP分开居住,因此不理解多维数组。

There is no mechanism in 'simple' HTTP (multipart/form-data or application/x-www-form-urlencoded) to send 'arrays'. However, PHP interprets the [ & ] characters in key-value pairs as special. PHP is alone in that AFAIK, it's not a HTTP mechanism, it's just the parsing of input PHP does, as is replacing .'s in the name of values with _. Curl is a 3rd party package which lives seperately from PHP, and as such does not understand multidimensional arrays.

这篇关于PHP和卷曲,深阵列发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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