In this article, we will learn how to allow multiple files uploads in HTML forms.
我們使用多個屬性,以允許在HTML表單中進行多個檔案上傳。多個屬性適用於電子郵件和文件輸入類型。
If you want to allow a user to upload the file to your website, you need to use a file upload box, also known as a file, select box. This is created using the element and the type of attribute is set to file.
以下是在HTML表單中選擇多個檔案上傳的語法。
<input type="file" name="name" multiple>
以下是HTML表單中選擇多個檔案上傳的範例程式。
<!DOCTYPE html> <html> <head> <title>Upload multiple files</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form> <input type="file" name="name" multiple><br><br> <br> <input type="submit" value="Submit"> </form> </body> </html>
以下是上述範例程式的輸出,其中在輸入欄位中未選擇任何檔案。
We have chosen only one file in the input field. Below is the output shows the file, we have chosen.
我們也可以選擇盡可能多的檔案。下面的輸出顯示我們選擇的文件數量。
The below syntax work same as the above-mentioned syntax. We assign ‘multiple’ attribute with the value of multiple for selecting multiple files in the input field.
以下是在HTML表單中選擇多個檔案上傳的語法。
<input type="file" name="name" multiple=>
以下是在HTML表單中選擇多個檔案上傳的範例程式。
<!DOCTYPE html> <html> <head> <title>Upload multiple files</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form> <input type="file" name="name" multiple="multiple"><br><br> <br> <input type="submit" value="Submit"> </form> </body> </html>
正如我們在輸出中看到的,我們已經選擇了四個檔案進行上傳。
以上是如何在HTML表單中允許多個檔案上傳的詳細內容。更多資訊請關注PHP中文網其他相關文章!