略微加速

略速 - 互联网笔记

用PHP POST提交文件

2020-12-11 leiting (3040阅读)

标签 PHP

if($_FILES['icon_img'])
{
    $file=file_get_contents($_FILES['icon_img']['tmp_name']);
    $filename=str_replace('%','',rawurlencode($_FILES['icon_img']['name']));
    $filetype=$_FILES['icon_img']['type'];
    $content = "------neirongqianmianyaoduojialianggegang\r\n".
    "Content-Disposition: form-data; name=\"purchase_image_file\"; filename=\"$filename\"\r\n".
    "Content-Type: $filetype\r\n\r\n";
    $content.="$file\r\n------neirongqianmianyaoduojialianggegang--\r\n";
    $options = array(
        'http' => array(
        'method' => 'POST',
        'header' => "Content-Type: multipart/form-data; boundary=----neirongqianmianyaoduojialianggegang\r\n",
        'content' => $content,
        )
    );
    $res=json_decode(file_get_contents('http://www.xxx.com/upload', false, stream_context_create($options)),true);
}


北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3