Trang Chủ | Diễn Đàn | Thành Viên (Đăng Ký) | Tìm Kiếm | Tutorial Room
PHP - Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
Hỏi đáp, trao đổi về lập trình PHP.
- Các câu hỏi về tìm hosting hỗ trợ PHP xin hãy gởi vào box Web Hosting.
- Các câu hỏi về tìm chương trình forum, guestbook, hướng dẫn sử dụng, cấu hình các script viết bằng PHP...xin hãy gởi vào box Web Application.
First page Previous page  (Page 1 )   1   Next page Last page
Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
Member
Member since
21:41 16-01-2008
Posts: 104
Fantasy Points: 376
Rank
question Posted at 00:09 11-09-2008 Move Move Topic   Pin/Unpin Pin Topic   Lock Lock Topic
Chào các bạn,
Mình gặp vấn đề khi upload 1 file có dung lượng lớn hơn post_max_size (post_max_size=8MB) thì PHP tự reset biến $_POST nên không thể "bắt" thông báo lỗi được.

Theo mình biết thì khi upload file trong PHP sẽ phụ thuộc chủ yếu vào 3 yếu tố:
- post_max_size
- upload_max_filesize
- excution time

Vậy làm thế nào để có thể xử lý được trong trường hợp này với yêu cầu: post_max_size >= upload_max_filesize >= upload filesize

Rất mong nhận được câu trả lời của các bạn.
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,740 time(s). 1 direct repli(es) and 5 indirect repli(es).
Title Poster
question Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
 
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
NBThanh
Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
Forum Moderator
Member since
20:03 17-08-2001
Posts: 18,047
Fantasy Points: 154,606
Rank
answer Posted at 00:34 11-09-2008
Reply to Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size (DoNamKhanh)
Tuỳ vào mức độ "xử lý" mà bạn mong muốn. Hiện tại thì PHP để mã lỗi vào trong $_FILES. Căn cứ vào mã lỗi bạn có thể biết là nó vượt quá post_max_size hay không để đưa ra câu thông báo thích hợp.
Tham khảo thêm: http://www.vninformatic...biet-ngay-thang-nam.html#1023614589
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,739 time(s). 1 direct repli(es) and 4 indirect repli(es).
Title Poster
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
 
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
DoNamKhanh
Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
Member
Member since
21:41 16-01-2008
Posts: 104
Fantasy Points: 376
Rank
answer Posted at 01:05 11-09-2008
Reply to Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size (NBThanh)
Cảm ơn anh Thành đã trả lời nhưng trong phần Handling file uploads, mục Error Messages Explained (http://vn.php.net/manua...s.file-upload.errors.php) thì em thấy họ không nhắc gì đến error code khi dung lượng của dữ liệu qua POST method lớn hơn giá trị post_max_size set trong php.ini???

Em định check như thế này:
$maxPostSize = ini_get('post_max_size');
if($maxPostSize < $upload_file["size"]) {
    drupal_set_message("You have defined a maximum size for file uploads which exceeds the allowed size for POST requests. Therefore the file uploads can not be larger than ".$maxPostSize.".</li>", 'error');
}

Nhưng khi chạy thì nó không nhảy đc vào lệnh If này vì $_POST đã bị reset hết :(

p/s: không hiểu ý của anh khi đưa em link đó :p Vấn đề của em là không biết "dựa vào dấu hiệu nào" để biết file upload lên vượt quá post_max_size ạ.
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,734 time(s). 1 direct repli(es) and 3 indirect repli(es).
Title Poster
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
 
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
NBThanh
Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
Forum Moderator
Member since
20:03 17-08-2001
Posts: 18,047
Fantasy Points: 154,606
Rank
answer Posted at 01:22 11-09-2008
Reply to Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size (DoNamKhanh)
PHP có 2 limit: POST và UPLOAD. Nếu upload thì em phải check dung lượng file so với cái upload_size_limit chứ :-)
Mà thực ra em cũng không cần check như thế vì PHP đã làm rồi, nếu $_FILES['userfile']['error'] == UPLOAD_ERR_INI_SIZE thì tức là file upload có dung lượng vượt quá qui định trong file php.ini

Bình thường post_max_size sẽ lớn hơn upload_max_size, tuy nhiên "strange behavior" sẽ xảy ra khi upload_max_size < post_max_size. "Strange" ở đây là vì PHP không qui định rõ nó xẽ xử lý sao trong trường hợp này, mỗi version của PHP có thể nó ứng xử khác nhau.
Nhưng trường hợp này hiếm khi xảy ra :-)
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,731 time(s). 1 direct repli(es) and 2 indirect repli(es).
Title Poster
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
 
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
DoNamKhanh
Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
Member
Member since
21:41 16-01-2008
Posts: 104
Fantasy Points: 376
Rank
answer Posted at 01:49 11-09-2008
Reply to Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size (NBThanh)
Đó đó, đúng cái em cần hỏi anh ạ.
Cấu hình hiện tại trên local của em như sau:
post_max_size = 8M
upload_max_size = 2M

Phần check upload file size của em chạy ổn với trường hợp file upload có dung lượng >2 và <8M (mảng $_FILES['userfile']['error'] có giá trị). Tuy nhiên nếu vượt quá 8MB thì chịu, trang hiện ra như kiểu no action, chẳng có gì để so sánh cả :(
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,729 time(s). 1 direct repli(es) and 1 indirect repli(es).
Title Poster
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
 
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
NBThanh
Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
Forum Moderator
Member since
20:03 17-08-2001
Posts: 18,047
Fantasy Points: 154,606
Rank
answer Posted at 01:53 11-09-2008
Reply to Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size (DoNamKhanh)
donamkhanh:
Đó đó, đúng cái em cần hỏi anh ạ.
Cấu hình hiện tại trên local của em như sau:
post_max_size = 8M
upload_max_size = 2M

Phần check upload file size của em chạy ổn với trường hợp file upload có dung lượng >2 và <8M (mảng $_FILES['userfile']['error'] có giá trị). Tuy nhiên nếu vượt quá 8MB thì chịu, trang hiện ra như kiểu no action, chẳng có gì để so sánh cả :(

Theo tài liệu của PHP (http://vn.php.net/manual/en/ini.core.php#ini.post-max-size) thì khi POST size vượt quá giá trị cho phép thì PHP nó bỏ sạch (coi như là không có post gì hết).
Và PHP cũng có gợi ý cách check, ngoài ra bạn cũng có thể check bằng cách thấy action là POST mà mọi thứ nó empty thì có thể coi như là rơi vào trường hợp này.
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,727 time(s). 1 direct repli(es) and 0 indirect repli(es).
Title Poster
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
 
answer Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
DoNamKhanh
Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size
Member
Member since
21:41 16-01-2008
Posts: 104
Fantasy Points: 376
Rank
answer Posted at 02:28 11-09-2008
Reply to Re: Hỏi về cách xử lý upload file nếu filesize vượt quá post_max_size (NBThanh)
NBThanh:
Và PHP cũng có gợi ý cách check, ngoài ra bạn cũng có thể check bằng cách thấy action là POST mà mọi thứ nó empty thì có thể coi như là rơi vào trường hợp này.

Rất cảm ơn anh, vấn đề được giải quyết chỉ với mấy dòng code đơn giản như sau :(
if(isset($_GET['processed']) && !count($_POST)) {
  die('Error message here...');
}
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,725 time(s). 0 direct repli(es) and 0 indirect repli(es).
First page Previous page  (Page 1 )   1   Next page Last page

Permissions: Create Topic: No  |  Reply Topic: No  |  Attach File: No  |  Make Poll: No

Vietnamese Keyboard: AUTO TELEX VNI VIQR VIQR* OFF

Go top || Print page ||

All logos, trademarks and graphics artwork in this site are property of their respective owners.
Opinions expressed in articles within this site are those of their owners and may not reflect the opinion of TXBB.

TXBB: Home - Disclaimer - Help - Contact
Copyright (C) 2000-2006 TXBB. All rights reserved.

TreXanh Bulletin Board v2.0 (Build: #332 Nov 21, 2006)

DEBUG INFORMATION
Execution 0.134s - SQL used 5s - Concurrent process(es) 0