問題描述
我有一個基本的、眾所周知的多文件上傳表單.類似的東西...
I have that basic, well known multiple file upload form. Something like that...
<input type="file" multiple="multiple" name="something[]" />
有沒有辦法(最好是硬編碼選項)來限制用戶可以選擇的文件數量?我所說的限制是指嚴格阻止,而不僅僅是在數量超過時發出警告.
Is there a way (preferable a hard coded option) to limit the number of files that user can select? By limit i mean strictly blocked, not just a warning if number is exceeded.
提前致謝.:)
推薦答案
您可以實現一個 javascript 解決方案來檢查已選擇的文件數量,然后您可以使用它來禁止上傳到服務器.不過,對于這個問題,實際上只有客戶端解決方案,因為實際上沒有什么可以阻止用戶將這些文件發布到您的 php 腳本中.您可以指定最大上傳大小限制,但它并不特定于正在上傳的文件數量.
You can implement a javascript solution to check the number of files that have been selected, which you can then use to forbid uploading to the server. There are really only going to be client-side solutions to this problem though, as there is really nothing stopping a user from posting these files to your php script anyway. You can specify a maximum upload size limit, but it isn't specific to the number of files that are being uploaded.
您最好的辦法是實施一些 javascript 檢查,為您的 http 服務器(或在 PHP 中)指定一個合理的最大上傳大小,然后忽略任何超過您的最大數量上傳的文件.
Your best bet is to implement some javascript checking, specifying a reasonable maximum upload size for your http server (or in PHP), and then ignoring any file uploaded if it exceeds your maximum count.
在此處閱讀 HTML5 文件 API 以限制所選文件的數量:http://dev.w3.org/2006/webapi/FileAPI/
Read about the HTML5 File API here to restrict the count of selected files: http://dev.w3.org/2006/webapi/FileAPI/
這里是 php.ini 文檔,它解釋了如何對上傳進行大小限制:http://php.net/manual/en/ini.core.php
Here is the php.ini docs which explain how to make a size limitation on uploads: http://php.net/manual/en/ini.core.php
正如評論中所建議的,請查看:http://php.net/manual/en/ini.core.php#ini.max-file-uploads
As was suggested in the comments, check out: http://php.net/manual/en/ini.core.php#ini.max-file-uploads
這篇關于統計和限制上傳文件的數量(HTML文件輸入)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!