免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6557 | 回复: 3
打印 上一主题 下一主题

请教怎么用curl上传文件? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-30 11:40 |只看该作者 |倒序浏览
请教各位大哥怎么用curl上传文件啊!我都整了一天没搞定:

以下是用CURL提交表单的代码:那位大哥能帮我修改一下

  1. <?php
  2. //请求页面
  3. $address=array(
  4. 'street'=>$_POST['street'],
  5. 'city'=>$_POST['city']
  6. );


  7. $ch = curl_init("http://211.151.109.51/work/test1.php");
  8. curl_setopt($ch,CURLOPT_POST,1);
  9. curl_setopt($ch,CURLOPT_POSTFIELDS,$address);
  10. $ret = curl_exec($ch);
  11. curl_close($ch);


  12. ?>
复制代码

论坛徽章:
0
2 [报告]
发表于 2006-04-30 12:54 |只看该作者
原帖由 xiao_ye 于 2006-4-30 11:40 发表
请教各位大哥怎么用curl上传文件啊!我都整了一天没搞定:

以下是用CURL提交表单的代码:那位大哥能帮我修改一下

...


  1. <?php
  2. $uploaded_file = "test.gif";

  3. //请求页面
  4. $address=array(
  5. 'street'=>$_POST['street'],
  6. 'city'=>$_POST['city'],
  7. 'upfile'=>"@$uploaded_file";
  8. );


  9. $ch = curl_init("http://211.151.109.51/work/test1.php");
  10. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  11. curl_setopt($ch, CURLOPT_HEADER, 0);
  12. curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  14. curl_setopt($ch, CURLOPT_POSTFIELDS, $address);
  15. $ret = curl_exec($ch);
  16. curl_close($ch);

  17. ?>

复制代码

论坛徽章:
0
3 [报告]
发表于 2006-04-30 13:14 |只看该作者

回复 2楼 dreammaker 的帖子

请问: $uploaded_file = 是用$_FILES['file']接收的吗?

我上传文件的代码是:

  if(!move_uploaded_file($_FILES['upfile']['tmp_name'], $upload_pathfile ))   //上传文件;
              {
                         error_report('附件上传不成功,请重新上传!') ;
              }

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
4 [报告]
发表于 2006-05-01 20:41 |只看该作者
  1. <?php

  2.    $post_data = array();
  3.    
  4.    $post_data['pictures[0]'] = "@cat.jpg";
  5.    $post_data['pictures[1]'] = "@dog.jpg";
  6.    

  7.    $ch = curl_init();
  8.    curl_setopt($ch, CURLOPT_URL, "http://my.domain.com/my_url.php" );
  9.    curl_setopt($ch, CURLOPT_POST, 1 );
  10.    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  11.    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12.    $postResult = curl_exec($ch);

  13.    if (curl_errno($ch)) {
  14.        print curl_error($ch);
  15.    }
  16.    curl_close($ch);
  17.    print "$postResult";
  18. ?>
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP