Upload pictures on php curl

upload pictures using curl. Keep reporting timeout errors.

Operation timed out after 30000 milliseconds with 0 bytes received

my curl function is as follows:

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;
    }
}
< hr >

2.php wrote only one line of code

print_r($_FILES);
< hr >

php version is: php-7.0.12-nts

the size of the test image is only 100k

< hr >

Please don"t hesitate to give us your advice and thank you!

Mar.23,2021

curl set the option to increase the limit time a little bit to see if it can succeed

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

PS: do not upload files that are too large

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34cca-404cd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34cca-404cd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?