1. <?php
    2. /** 二进制流生成文件
    3. * $_POST 无法解释二进制流,需要用到 $GLOBALS['HTTP_RAW_POST_DATA'] php://input
    4. * $GLOBALS['HTTP_RAW_POST_DATA'] php://input 都不能用于 enctype=multipart/form-data
    5. * @param String $file 要生成的文件路径
    6. * @return boolean
    7. */
    8. function binary_to_file($file){
    9. $content = $GLOBALS['HTTP_RAW_POST_DATA']; // 需要php.ini设置
    10. if(empty($content)){
    11. $content = file_get_contents('php://input'); // 不需要php.ini设置,内存压力小
    12. }
    13. $ret = file_put_contents($file, $content, true);
    14. return $ret;
    15. }
    16. // demo
    17. binary_to_file('photo/test.png');
    18. ?>

    在上传时如果遇到大文件

    1. ini_set('memory_limit','128G');