Answer the question
In order to leave comments, you need to log in
Is there a way to check the image size before uploading to the server?
There is an API server on nginx (ubuntu) with php. Is it possible to check the image size before uploading? Or if the image size is more than 2mb then send the image size to php script. The server has a 2MB limit. Now if the user tries to upload more than 2mb, it gives an error 413 Request Entity Too Large. Can I somehow get (catch) this error in PHP script? Do not issue a 413 error, but simply return to the client for example.{'size_error':true}
Answer the question
In order to leave comments, you need to log in
function getFileSize($url)
{
$cURLsession = curl_init();
curl_setopt($cURLsession, CURLOPT_URL, $url);
curl_setopt($cURLsession, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($cURLsession, CURLOPT_HEADER, TRUE);
curl_setopt($cURLsession, CURLOPT_NOBODY, TRUE);
$data = curl_exec($cURLsession);
if(($curlResult = curl_exec($cURLsession)) === false)
{
echo "Ошибка при получении данных: ".curl_error($cURLsession).". С ".$url;
}
$responseType = curl_getinfo($cURLsession, CURLINFO_CONTENT_TYPE);
$fileSize = curl_getinfo($cURLsession, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($cURLsession);
return $fileSize;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question