PHP curl模拟form[type=file]上传文件
<?php $contents =<<<‘TEXT’ 上传文件在数据报中应该是 Content-Disposition: form-data; name="file1"; filename="3.txt" Content-Type: 文档类型 文件内容 TEXT; $varname = 'file1'; $name = '3.txt'; $type = 'text/plain'; $key = "$varname\"; filename=\"$name\r\nContent-Type: $type\r\nAccept: \""; $fields[$key] = $contents; $fields['dd'] = "pupu"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://10.16.15.225/qa/test1.php"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST" ); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $s = curl_exec ($ch); curl_close ($ch); echo $s; ?>
服务端$_POST数组结果:
array(1) { ["dd"]=> string(4) "pupu" }
$_FILES数组结果:
array(1) { ["file1"]=> array(5) { ["name"]=> string(5) "3.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpI7dkkA" ["error"]=> int(0) ["size"]=> int(380) } }
相关推荐
- rsync 的核心算法
- Posted on 02月24日
- Mysql临时文件存放空间不足问题解决
- Posted on 04月13日
- lnmp下nginx出现502 Bad Gateway问题解决汇总
- Posted on 05月13日
- Linux中TCP连接过程状态简介
- Posted on 01月05日