dongmaonao0505 2010-05-07 16:35
浏览 73
已采纳

curl post picture multipart / form-data,php cURL需要帮助!

I'm trying to upload a picture to a specific website using php cURL but I don't really understand what parameters do I need to send because the data looks a bit weird . Here is what i got with the http analyzer
Type : multipart/form-data; boundary=---------------------------182983931283 -----------------------------182983931283 Content-Disposition: form-data; name="file"; filename="Blue hills.jpg"
Content-Type: image/jpeg

Here appears the souce of the image itself like "ÿØÿàÿØÿàÿØÿàÿØÿàÿØÿàÿØÿà" -----------------------------182983931283 Content-Disposition: form-data; name="action" images -----------------------------182983931283 Content-Disposition: form-data; name="anonymous_email"

Y -----------------------------182983931283 Content-Disposition: form-data; name="site_id"

1 -----------------------------182983931283 and so on other parameters. The issue that I have is that I don't understand what is the boundary, where do I get it from (because it doesn't appear in the html document that generates the POST and how should I make the post . If you would give me a simple example to post the above parameters to http://example.com I will definitely get the trick . Currently I'm using the following function to make the post :

   function processPicturesPage($title, $price, $numbedrooms, $description) {        //Set the login parameters and initiate the Login process    
    $fields = array(

"changedImages" => "", "site_id" => "1", "posting_id" => "", "current_live_date" => "", "images_loaded" => "", "image_actions" => "", "title" => $title,

); foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); $URL = "http://www.example.com/cgi-bin/add_posting.pl"; return $this->processCurlrequest($URL, count($fields), $fields_string); }

and in the processCurlrequest I have the curl options (cookies etc) and url .

  • 写回答

1条回答 默认 最新

  • duancan1950 2010-05-07 17:08
    关注

    When sending multipart data, boundaries are used as separators between each field. These boundaries are automatically created by cURL and you shouldn't need to worry about them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵