# PHP post_max_size issue


Hôm nay tôi gặp phải 1 "tình huống" khá là củ chuối. Phần upload file (thật ra là upload file để update lại các store - khá nhiều, hiện tại là 1500 store) có validate file size, file type. Tôi test "khá kỹ " ở local & mọi thứ đều ổn. Thông số local của tôi như sau:

- Windows XP/Vertrigo
- post\_max\_size = 100M
- upload\_max\_size = 20M

Khi up 1 file có dung lượng quá 20MB (**<100MB**) thì hệ thống hiện thông báo rất đẹp với nội dung là bạn đã upload quá dung lượng quy định bla bla...:-@

Thế nhưng sau khi request done trên PMS (project management system), bên test report lại là khi upload 1 file lớn hơn 16MB thì chẳng hiện gì cả, không lỗi & giống như tự F5 lại trang.

Xem phpinfo của môi trường trên testing thì như sau:

- post\_max\_size = 8M
- upload\_max\_size = 16M

Vậy là dung lượng vượt quá post\_max\_size rồi, và PHP đã làm thế này đối với đoạn code của tôi:

> If the size of post data is greater than post\_max\_size, the [$\_POST](http://vn.php.net/manual/en/reserved.variables.post.php) and [$\_FILES](http://vn.php.net/manual/en/reserved.variables.files.php) [superglobals](http://vn.php.net/manual/en/language.variables.superglobals.php) are empty

Thế cho nên đoạn code:

$postMaxSize = int\_get('post\_max\_size');
if($postMaxSize < $userFile\['size'\]) {
//process error
}

chẳng hoạt động gì cả :(( Trên php.net có 1 trick để xử lý trường hợp này:

> 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.

Và đây là đoạn code của tôi:

if(isset($\_GET\['processed'\]) && !count($\_POST)) {
  die('Error message here...');
}

Chạy ngon ;)

_Rất cảm ơn anh [NBThanh](http://diendantinhoc.org/forum/topic/63184/Hoi-ve-cach-xu-ly-upload-file-neu-filesize-vuot-qua-post-max-size.html?zone=4) (Nguyễn Bá Thành) đã giúp đỡ em khắc phục vấn đề này :)_

