Home > php教程 > PHP源码 > body text

通过base64 上传文件

PHP中文网
Release: 2016-05-20 12:58:05
Original
1585 people have browsed it

1.代码

$url = "http://127.0.0.1/user/update_user_profile.php";
    $post_data = [
        'user_id'=>'100010',
        'sign'=>'1d4d8920ce87b5ef44a67870556dd35a',
        'category_type'=>'1',
        'title'=>'title1',
        'source'=>'source111',
        'content'=>'content1111',
        'image_list'=>'data:image/png;base64,iVBOElFTkSuQmCC|w*h',
    ];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // post数据
    curl_setopt($ch, CURLOPT_POST, 1);
    // post的变量
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $output = curl_exec($ch);
    curl_close($ch);
    //打印获得的数据
    print_r($output);
Copy after login

2. 处理客户端提交的post数据

foreach($param_image_list as $param_image_item) {
        $param_image_data = $param_image_item['image_data'];
        $param_image_width = $param_image_item['w'];
        $param_image_height = $param_image_item['h'];
        $s = base64_decode(str_replace('data:image/png;base64,', '', $param_image_data));
        $image_path = '../uploadimg/'.md5($param_user_id).'_'.time().'_'.$index.'.png';
        file_put_contents($image_path, $s);
        $index ++;
        array_push($image_info_list,$image_path.'|'.$param_image_width.'|'.$param_image_height);
    }
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!