ThinkPHP attachment Upload class UploadFile custom attribute settings

Source: Internet
Author: User
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
  1. Mport ("ORG. Net. UploadFile ");
  2. $ Upload = new UploadFile ();
  3. $ Upload-> maxSize = 500*1024;
  4. $ Upload-> thumb = false;
  5. $ Upload-> autoSub = true;
  6. $ Upload-> subType = "date ";
  7. $ Upload-> dateFormat = "Ymd ";
  8. $ Upload-> saveRule = "uniqid ";
  9. $ Upload-> allowExts = explode (',', 'PNG, jpg, jpeg, gif ');
  10. $ 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.