当使用curl @ 来上传文件时
- <?php
- $fileUploadPostParams = array(
- 'file' => '@/123.jpg'
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://tkxxd.com/post.php');
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fileUploadPostParams);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- echo curl_exec($ch);
复制代码
接收到文件类型变掉
- array (
- 'file' =>
- array (
- 'name' => '123.jpg',
- 'type' => 'application/octet-stream',
- 'tmp_name' => '/tmp/php7Zr0bN',
- 'error' => 0,
- 'size' => 30163,
- ),
- )
复制代码
type变为 application/octet-stream
不是image/jpeg 接收侧会判断为不合法,上传失败
解决方法:
通过在文件名后面加上";type=image/jpeg"解决了该问题,如'file' => '@/123.jpg;type=image/jpeg'
CURL 7.19.7支持此方法,7.16.0不支持此方法 |