Can you set the maximum file size for upload using the PHP built-in Curl function?

When using Curl from the command line, you can use the following command to limit the size of uploaded files to 250kb:

curl 'http://www.domain.com' --max-filesize 250000 

I cannot find the parameter when using PHP curl_init() and curl_setopt() .

Did I miss something?

+4
source share
2 answers

It is not possible to do this with the PHP built-in curl functions without a separate request to the web server hosting the file.

0
source

You can use callback

CURLOPT_READFUNCTION Pass a function that will be called to read data. Callback function prototype:

 string read_callback (resource ch, resource fd, long length) 

The ch parameter is a CURL session handle. The fd argument is a file descriptor passed to CURL using the CURLOPT_INFILE option. The length argument is the maximum length that can be returned. The function should return a string containing the read data. If the data length is greater than the maximum, then it will be truncated to the maximum length. Returning everything else but the string means EOF.

See curl_setopt .

+5
source

Source: https://habr.com/ru/post/1379401/


All Articles