E
E
Egor Tini2020-12-13 23:55:41
PHP
Egor Tini, 2020-12-13 23:55:41

Why is sometimes the picture that comes through curl not complete?

request

$file = new \CURLFile($dir, 'image/jpg', $name);
//        dd($file, $target_url);
        set_time_limit(0);
        $printname = 'print_'.$name;
        $handle = fopen($printname,'w+');

        $ch = curl_init($target_url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, [
            'file' => $file
        ]);
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);

//        curl_setopt($ch,CURLOPT_TIMEOUT, 600);
        curl_setopt($ch, CURLOPT_FILE, $handle);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_ENCODING, "");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        $raw=curl_exec($ch);
        $status = curl_getinfo($ch,  CURLINFO_RESPONSE_CODE);
        curl_close($ch);
        if($status === 200)
        {
            fwrite($handle, $raw);
            fclose($handle);
        }
        else
        {
            fclose($handle);
            dd('Err', $status);
        }


the picture that comes has a large weight of about 10mb and sometimes it seems that it cannot save it to the end
5fd67f8f6f8d6751324104.png

, but it looks like this in html (like the floor
5fd67fab12c1b648249614.png

of the picture) below the original sometimes the picture is normal

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2020-12-14
@dimonchik2013

set a longer timeout, corny not pumping

N
nokimaro, 2020-12-14
@nokimaro

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); 
curl_setopt($ch, CURLOPT_TIMEOUT, 0);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question