After setting the upload parameters, you can call the upload method of the UploadFile class to upload attachments. if the upload fails, false is returned and the getErrorMsg method is used to obtain the error message. if the upload is successful, you can call
- Mport ("ORG. Net. UploadFile ");
- $ Upload = new UploadFile ();
- $ Upload-> maxSize = 500*1024;
- $ Upload-> thumb = false;
- $ Upload-> autoSub = true;
- $ Upload-> subType = "date ";
- $ Upload-> dateFormat = "Ymd ";
- $ Upload-> saveRule = "uniqid ";
- $ Upload-> allowExts = explode (',', 'PNG, jpg, jpeg, gif ');
- $ Upload-> savePath = C ('mypicture _ path'). '/www/tkyouxi/com /';
The code above automatically generates sub-directories. Do not generate thumbnails
After the upload class is instantiated, you can set some Upload attributes (parameters). the supported attributes include:
MaxSize: the maximum file size (in bytes) uploaded by a file. the default value is-1.
SavePath: specifies the file storage path. if it is left empty, the path defined by the constant UPLOAD_PATH is used.
SaveRule: The storage rule for uploaded files. it must be a function name without any parameters, such as time and uniqid com_create_guid. However, the generated file name must be unique, the default value is uniqid.
HashType: hash verification method for uploading files. the default value is md5_file.
AutoCheck: whether to automatically detect attachments. the default value is automatic check.
UploadReplace: whether the file with the same name is overwritten
AllowExts: specifies the file suffix that is allowed to be uploaded (leave blank is unlimited). It is set using an array. the default value is an empty array.
AllowTypes: specifies the file type that can be uploaded. the default value is an empty array.
Thumb: Specifies whether to perform thumbnail processing on image files. the default value is false.
ThumbMaxWidth: The maximum width of a thumbnail. multiple values are separated by commas (,).
ThumbMaxHeight: the maximum height of a thumbnail. multiple values are separated by commas (,).
ThumbPrefix: the prefix of the thumbnail file. the default value is thumb _
ThumbSuffix: The file suffix of the thumbnail. it is blank by default.
ThumbPath: The storage path of the thumbnail. if it is left empty, the file upload directory is used.
ThumbFile: specifies the thumbnail file name.
ThumbRemoveOrigin: whether to delete the source image after the thumbnail is generated
AutoSub: whether to use subdirectories to save uploaded files
SubType: Create a subdirectory. the default value is hash. it can be set to hash or date.
DateFormat: specify the date format when the subdirectory mode is date.
HashLevel: the level of sub-directory storage. the default level is one layer.
The preceding attributes can be set directly, for example:
$ Upload-> thumb = true
$ Upload-> thumbMaxWidth = "50,200"
$ Upload-> thumbMaxHeight = "50,200"
The Image class supports generating thumbnails.
After setting the upload parameters, you can call the upload method of the UploadFile class to upload attachments. if the upload fails, false is returned and the getErrorMsg method is used to obtain the error message. if the upload is successful, you can call the getUploadFileInfo method to obtain the list of successfully uploaded attachments. Therefore, the returned value of the getUploadFileInfo method is an array, and each element is the uploaded attachment information. Each attachment is an array that records the following information, including:
Key: The name of the form uploaded by the attachment.
Savepath: save path of the uploaded file
Name: The original name of the uploaded file.
Savename: the name of the uploaded file.
Size: The size of the uploaded file.
Type: MIME type of the uploaded file
Extension: Suffix type of the uploaded file
Hash: hash verification string of the uploaded file
After the file is uploaded successfully, you can use the attachment information to access other data, for example, save it to the current data table or a separate attachment data table.