1 2 3 4 5 6 7 8 9 10 11 | <body> <form action="UploadFile.php" method="post" enctype="multipart/form-data"> <input type="file" name="fileUpload" /> <input type="submit" value="上传文件" /> </form> </body> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php header('Content-type:text/html; charset=utf-8'); //声明编码 $ch = curl_init(); $url = 'https://xxx.com/api/mobile/auto_upload.php?uid=9705459'; //post数据,使用@符号,curl就会认为是有文件上传 $curlPost = array('Filedata'=>'@/Users/finup/Documents/11.png'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); //POST提交 curl_setopt($ch, CURLOPT_POSTFIELDS,$curlPost); $data =curl_exec($ch); curl_close($ch); echo '<pre>'; var_dump($data); |
1 2 3 4 5 6 7 8 9 10 11 12 | Array ( [Filedata] => Array ( [name] => 11.png [type] => application/octet-stream [tmp_name] => /private/var/tmp/php936cex [error] => 0 [size] => 36663 ) ) |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |