Nasıl incelikle PHP'nin `post_max_size` aşan dosyaları işlemek için?

2 Cevap php

Ben bir e-postaya bir dosya verdiği bir PHP form üzerinde çalışıyor, ve incelikle yüklenen dosya çok büyük davalarını çalışıyorum.

upload_max_filesize ve post_max_size: Ben bir dosya yükleme Maksimum sayı boyutunu etkileyen php.ini iki ayarları olduğunu öğrendim.

Bir dosyanın boyutu aşarsa upload_max-filesize, PHP 0 olarak dosyanın boyutunu verir Bu iyi.; Bunun için kontrol edebilirsiniz.

O post_max_size aşarsa Ama, benim komut dosyası sessizce başarısız olur ve geri boş forma gider.

Is there any way to catch this error?

2 Cevap

Dan http://ca2.php.net/manual/en/ini.core.php#ini.post-max-size

If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. , and then checking if $_GET['processed'] is set.

PHP bir hata gönderir gibi Yani ne yazık ki, o görünmüyor. Bu öğleden boş $ _POST dizi gönderir beri komut geri boş form gidiyor neden Ve, yani - o bir POST olduğunu düşünmüyor. (Oldukça kötü bir tasarım kararı IMHO)

This commenter, aynı zamanda ilginç bir fikri vardır.

It seems that a more elegant way is comparison between post_max_size and $_SERVER['CONTENT_LENGTH']. Please note that the latter includes not only size of uploaded file plus post data but also multipart sequences.

max sonrası boyutunu aşan dosyaları işlemek / yakalamak için bir yol var, bu benim o ne oldu son kullanıcı söyler gibi, tercih edilen ve hatalı kim olduğunu ;)

    if(empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ //catch file overload error...
        $postMax = ini_get('post_max_size'); //grab the size limits...
        echo "<p style=\"color: #F00;\">\nPlease note files larger than {$postMax} will result in this error!<br>Please be advised this is not a limitation in the CMS, This is a limitation of the hosting server.<br>For various reasons they limit the max size of uploaded files, if you have access to the php ini file you can fix this by changing the post_max_size setting.<br> If you can't then please ask your host to increase the size limits, or use the FTP uploaded form</p>"; // echo out error and solutions...
        addForm(); //bounce back to the just filled out form.
}
elseif(// continue on with processing of the page...