tailieunhanh - Giải pháp thiết kế web động với PHP - p 20

UPLOADING FILES Figure 6-7. The class removes spaces from filenames and prevents files from being overwritten. Uploading multiple files You now have a flexible class for file uploads, but it can handle only one file at a time. Adding the multiple attribute to the file field s tag permits the selection of multiple files in an HTML5compliant browser. Older browsers also support multiple uploads if you add extra file fields to your form. The final stage in building the Ps2_Upload class is to adapt it to handle multiple files. To understand how the code works, you need to see what happens to. | UPLOADING FILES Figure 6-7. The class removes spaces from filenames and prevents files from being overwritten. Uploading multiple files You now have a flexible class for file uploads but it can handle only one file at a time. Adding the multiple attribute to the file field s input tag permits the selection of multiple files in an HTML5-compliant browser. Older browsers also support multiple uploads if you add extra file fields to your form. The final stage in building the Ps2_Upload class is to adapt it to handle multiple files. To understand how the code works you need to see what happens to the _FILES array when a form allows multiple uploads. How the _FILES array handles multiple files Since _FILES is a multidimensional array it s capable of handling multiple uploads. In addition to adding the multiple attribute to the input tag you need to add an empty pair of square brackets to the name attribute like this input type file name image id image multiple Support for the multiple attribute is available in Firefox Safari 4 Chrome 4 and Opera 10. At the time of this writing it is not supported in any version of Internet Explorer but that might change once the final version of IE9 is released. If you need to support older browsers omit the multiple attribute and create separate file input fields for however many files you want to upload simultaneously Give each input tag the same name attribute followed by square brackets. As you learned in Chapter 5 adding square brackets to the name attribute submits multiple values as an array. You can examine how this affects the _FILES array by using or in the ch06 folder. Figure 6-8 shows the result of selecting four files in an HTML5- 171 CHAPTER 6 compliant browser. The structure of the _F ILES array is the same when a form uses separate input fields that share the same name attribute. Download from Wow eBook Figure 6-8. The _FILES array can upload multiple files in a

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
18    120    0    23-11-2024
89    125    0    23-11-2024
54    143    1    23-11-2024