用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2472|回复: 1
收起左侧

[已解决] CI会自动截断POST上来的二进制数据?

[复制链接]
发表于 2012-1-31 18:41:25 | 显示全部楼层 |阅读模式
a.php
PHP复制代码
 
echo bin2hex(file_get_contents('./logo.gif')).'<hr />';
$ch=curl_init('http://localhost/b.php');    
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
        array('uname'=>'wqfghgfh','file'=>file_get_contents('./logo.gif'))
    );
    $data=curl_exec($ch);
    curl_close($ch);
    echo $data;
 
 
复制代码


b.php:
PHP复制代码
 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
 
class Avatar  {
    public function __construct(){
 
    }
 
    public function upload()
    {
        die(bin2hex($_POST['file']));
    }
 
}
 
 
复制代码

执行a.php发现输出的16进制结果根本对应不上。
但如果把b.php中的upload方法直接放到根目录下的index.php,把a.php中的url改成index.php就是OK的,怎么回事呢?
发表于 2012-2-1 12:42:02 | 显示全部楼层
你这个需求建议使用“上传”,而不是POST二进制数据。
curl是支持上传一个文件到服务器的。
我记得是POST的时候加个 'key' => '@文件名' 就行了。

本版积分规则