donglv1831 2015-08-21 19:23
浏览 47
已采纳

PHP cURL文件上传到网站

Hello I'm having problems uploading a file to the site bellow, I have inspected the elements and added them to the $data file, I'm fairly new to this, so please guide me.

function upload($url,$data)
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/xampp/htdocs/curl_upload/cookies.txt");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "C:/xampp/htdocs/curl_upload/cookies.txt");
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);

    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);



    $result = curl_exec($ch);   


    curl_close($ch);

    return $result;

}

$data = array("file_0"=>"@C:\files\somerarfile.rar","submit_btn"=>" Upload! ");

echo upload("http://180upload.com/",$data);
  • 写回答

1条回答 默认 最新

  • dream_life5200 2015-08-21 19:45
    关注

    Have you tried this on a live domain? Everything appears to be in shape, maybe there's a problem with the local php.ini, filesize or your operating system (with its security).

    Try on a live (sub)domain.

    To set you max filesize, try

    <?php
    ini_set('upload_max_filesize', '40M');
    ini_set('post_max_size',       '40M');
    ?>
    

    Obviously, set the values to whatever you need.

    With your upload page, have you tried logging all the POST, GET, FILES variables?

    What I do when I'm debugging and something doesn't want to work is:

    <?php
    $f = fopen("access.log", "a+");
    $data = print_r($_REQUEST,1);
    fwrite($f, $data);
    fclose($f);
    ?>
    

    Same with $_FILES. If there's an access log with the information, I know the page is being reached, everything is being sent but I'm handling it wrong.

    If there's no file then, obviously, the page isn't getting reached.

    Hope this helps

    Mark

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

报告相同问题?

悬赏问题

  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。
  • ¥40 宿舍管理系统设计(c#)
  • ¥15 MATLAB卫星二体模型仿真
  • ¥15 怎么让数码管亮的同时让led执行流水灯代码
  • ¥20 SAP HANA SQL Script 。如何判断字段值包含某个字符串
  • ¥85 cmd批处理参数如果含有双引号,该如何传入?
  • ¥15 fx2n系列plc的自控成型机模拟
  • ¥15 时间序列LSTM模型归回预测代码问题
  • ¥50 使用CUDA如何高效的做并行化处理,是否可以多个分段同时进行匹配计算处理?目前数据传输速度有些慢,如何提高速度,使用gdrcopy是否可行?请给出具体意见。