鍍金池/ 問答/PHP  Linux  網(wǎng)絡(luò)安全/ php curl 上傳圖片

php curl 上傳圖片

利用curl上傳圖片。一直報(bào)超時(shí)錯(cuò)誤。

Operation timed out after 30000 milliseconds with 0 bytes received

我的curl函數(shù)如下:

function myCurl($data, $file = null)
{
    if (!empty($file)) {
       $file_obj = curl_file_create(realpath($file), 'image/png', '550759_yuan521.png');
       $data['imgs'] = $file_obj;
       $data = http_build_query($data);
    }
    $opt = [
        CURLOPT_URL => 'http://localhost/test/2.php', // 測試地址
        CURLOPT_POST => true,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER => 0,
        CURLOPT_POSTFIELDS => $data,
        CURLOPT_SSL_VERIFYPEER => 0
    ];
    $ch = curl_init();
    curl_setopt_array($ch, $opt);
    $output = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);
    if ($error) {
        return $error;
    } else {
        return $output;
    }
}

2.php 只寫了一行代碼

print_r($_FILES);

php版本是:php-7.0.12-nts

測試圖片大小只有:100k


請(qǐng)大神不吝賜教,拜謝!

回答
編輯回答
爛人

curl設(shè)置一下選項(xiàng),讓限制時(shí)間加大一點(diǎn),看看能不能成功

curl_setopt($ch, CURLOPT_TIMEOUT,100); // 100s 

PS:不要上傳太大的文件

2018年4月25日 16:48