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

UPLOADING FILES • • • • • • • Check the error level. Verify on the server that the file doesn t exceed the maximum permitted size. Check that the file is of an acceptable type. Remove spaces from the filename. Rename files that have the same name as an existing one to prevent overwriting. Handle multiple file uploads automatically. Inform the user of the outcome. You need to implement these steps every time you want to upload files, so it makes sense to build a script that can be reused easily. That s why I have chosen to use a custom class | UPLOADING FILES Check the error level. Verify on the server that the file doesn t exceed the maximum permitted size. Check that the file is of an acceptable type. Remove spaces from the filename. Rename files that have the same name as an existing one to prevent overwriting. Handle multiple file uploads automatically. Inform the user of the outcome. You need to implement these steps every time you want to upload files so it makes sense to build a script that can be reused easily. That s why I have chosen to use a custom class. Building PHP classes is generally regarded as an advanced subject but don t let that put you off. I won t get into the more esoteric details of working with classes and the code is fully explained. Although the class definition is long using the class involves writing only a few lines of code. A class is a collection of functions designed to work together. That s an oversimplification but it s sufficiently accurate to give you the basic idea behind building a file upload class. Each function inside a class should normally focus on a single task so you ll build separate functions to implement the steps outlined in the previous list. The code should also be generic so it isn t tied to a specific web page. Once you have built the class you can reuse it in any form. If you re in a hurry the finished class is in the classes completed folder of the download files. Even if you don t build the script yourself read through the descriptions so you have a clear understanding of how it works. Defining a PHP class Defining a PHP class is very easy. You use the class keyword followed by the class name and put all the code for the class between a pair of curly braces. By convention class names normally begin with an uppercase letter and are stored in a separate file. It s also recommended to prefix class names with an uncommon combination of 3-4 letters followed by an underscore to prevent naming conflicts see http manual en .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG