普通网友 2010-10-15 22:44
浏览 39
已采纳

如何防止curl上传

There are many questions and guides on how to get cURL to DO file uploads, but what I'm asking today, is how to NOT get it to do that.

According to the curl options docs on php.net, curl "knows" to attempt a file upload by when a param starts with "@" then the local file path

This is all well and fine, but what do you do if you need to POST something with the literal text that starts with @ and NOT want to do a upload?

I'm sending the post data like this

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param_array);

and my params look like this (truncated for simplicity)

Array
(
    [action] => "edit"
    [title] => "my_pagename"
    [text] => "@disabled"
)

(before anyone asks, yes, this is for a mediawiki api call, but its not relevant)

right now, the curl_exec is just returning false (failing to find the file named "disabled" to post i think)

my code path for the rest of the params, and the actual POST is 100% tested fine, and has been working otherwise for over a year, so i'm 100% sure its this upload "bug"

  • 写回答

3条回答 默认 最新

  • douchongbang6011 2010-10-15 22:54
    关注

    I believe that if you post the query as a string, rather than an array, it should work:

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param_array));
    

    It's a bit of a hack, unfortunately...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示