Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the upload class UploadFile in ThinkPHP

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "ThinkPHP upload class UploadFile how to use", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "ThinkPHP upload class UploadFile how to use" this article.

The use of the upload class is very simple. If you are using the upload feature for the first time, you should note that the enctype attribute should be added to the form attribute in the html submission form, such as:

The copy code is as follows:

The UploadFile class of ThinkPHP is in the file.. / ThinkPHP/Extend/Library/ORG/Net/UploadFile.class.php:

The copy code is as follows:

/ / introduce UploadFile class

Import ('ORG.Net.UploadFile')

/ / instantiate the UploadFile class

$upload = new UploadFile ()

/ / set the file size

$upload-> maxSize = 3292200

/ / set the file saving rules to be unique

$upload- > saveRule = 'uniqid'

/ / set the format of the uploaded file

$upload-> allowExts = array ('jpg','png','jpeg')

/ / Save path

$upload- > savePath ='. / Public/Uploads/'

/ / A thumbnail needs to be generated, which is valid only for image files.

$upload- > thumb = true

/ / set the file prefix that needs to generate thumbnails

$upload- > thumbPrefix = 'masked thumbnails; / / production thumbnails can also generate one or more thumbnails as needed, and 2 can be:' masked memorials'.

/ / set the maximum width of the thumbnail

$upload- > thumbMaxWidth = '150' different settings for the two racquets: '150200'

/ / set the maximum height of the thumbnail

$upload- > thumbMaxHeight = '200'

/ / Delete the original image

$upload- > thumbRemoveOrigin = true

/ / error message returned when upload failed

If (! $upload- > upload ()) {

$this- > error ($upload- > getErrorMsg ())

} else {

$this- > success ('upload succeeded')

/ / get the information of uploaded files

$inf= $upload- > getUploadFileInfo ()

}

After setting up, you can easily upload files, and at the same time, the getUploadFileInfo of $upload can get information about uploaded files.

The above is all the content of the article "how to use the upload class UploadFile in ThinkPHP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report