假设server端上传文件处理脚本upload.php:
print_r($_POST);
print_r($_FILES);
print_r($_FILES);
1、使用 CURL 默认的方法
$file = realpath('temp.jpg'); //要上传的文件
$fields['f'] = <a href="mailto:'@'.$file">'@'.$file; // 前面加@符表示上传图片
$fields['f'] = <a href="mailto:'@'.$file">'@'.$file; // 前面加@符表示上传图片
$ch =curl_init();
curl_setopt($ch,CURLOPT_URL,'http://localhost/upload.php');
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$content = curl_exec($ch);
echo $content;
2、另类的做法
,有时我们需要将动态产生的内容当做文件上传到远程服务器,却又不想在本地服务器中构建临时文件。这样就有了这个另类的写法$varname = 'my';//上传到$_FILES数组中的 key
$name = '3.txt';//文件名
$type = 'text/plain';//文件类型
$name = '3.txt';//文件名
$type = 'text/plain';//文件类型
$key = "$varname\"; filename=\"$name\r\nContent-Type: $type\r\n";
$fields[$key] = $contents;
$ch =curl_init();
curl_setopt($ch,true);
$content = curl_exec($ch);
echo $content;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。