幻想曲 发表于 2012-1-31 18:41:25

CI会自动截断POST上来的二进制数据?

a.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 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的,怎么回事呢?

Hex 发表于 2012-2-1 12:42:02

你这个需求建议使用“上传”,而不是POST二进制数据。
curl是支持上传一个文件到服务器的。
我记得是POST的时候加个 'key' => '@文件名' 就行了。
页: [1]
查看完整版本: CI会自动截断POST上来的二进制数据?