博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

通过数据流上传文件

Posted on 2013-09-24 15:02  bug yang  阅读(816)  评论(0编辑  收藏  举报
    function test(&$id, &$img){
        $photodata = file_get_contents($img);
        $url = UPLOAD_IMAGE_URL;
//        if ($compress == 'N') {
//            $url = UPLOAD_IMAGE_URL . '&compress=n';
//        }

        $upload = http_parse_message(http_post_data($url, $photodata));
        $result = (array) $upload;
        if (!empty($result) && $result['body']) {
            $newPicId = explode("=", $result['body']);
            if (!empty($newPicId[1]) && $newPicId[1] > 0) {
                $result[0] = true;
                $id = Lib_String::filterBlank(($newPicId[1]));
            } elseif (!empty($newPicId[1]) && $newPicId[1] <= 0) {
                $result[0] = false;
                $result[1] = "上传失败";
            } else {
                $result[0] = false;
                $result[1] = "上传失败";
            }
        } else {
            $result[0] = false;
            $result[1] = "上传失败";
        }
    }

 

    public static function filterBlank($str) {
        mb_regex_encoding('utf-8');
        $str = mb_ereg_replace(' ', '', $str);
        return trim($str);
    }