Grabbing CSV over cURL in PHP

前端 未结 4 921
别跟我提以往
别跟我提以往 2021-01-17 05:04

Unfortunately, I cannot use either fopen or file_get_contents, so my working script has become a broken one using cURL:

$ch = curl_init();
curl_setopt($ch, C         


        
4条回答
  •  天命终不由人
    2021-01-17 05:43

    Ok there could be a couple of places which went wrong, most likely the $tmp variable will be your key.

    I am assuming the $url and $start variables have been declared correctly

    First thing I would suggest is to do something along the lines of:

        if( ! $tmp = curl_exec($ch))
            {
               echo curl_error($ch);
            } 
    
        else
        {
    
            header("Content-type: application/csv");
            header("Content-Disposition: attachment; filename=$start.csv");
            header("Pragma: no-cache");
            header("Expires: 0");
            echo $tmp;
        }
        curl_close($ch);
    

    Might give you an idea about what is going wrong

提交回复
热议问题