I recently found that it was very difficult to upload thinkphp images, and the code was forgotten. Later, I found a code example for uploading images on the Internet and performing paging operations for you to refer to. Recently, I found that it was very difficult to upload thinkphp images, and the code was forgotten. Later, I found a code example for uploading images and operating paging classes on the Internet for your reference.
If you think your project is not very good for testing code, you can create a new TestAction class.
1. execute the following code in TestAction. class. php of the controller.
//
Class TestAction extends
Action
{
Public function
Index ()
{
$ This-> display ();
}
Public function
Upload (){
If (! Empty ($ _ FILES )){
$ This-> _ upload ();
}
}
Public
Function
_ Upload (){
Import ("ORG. Net. UploadFile ");
$ Upload =
New
UploadFile ();
// Set the size of the uploaded file
$ Upload-> maxsize =
3145728;
// Set the Upload file type
$ Upload-> allowExts =
Explode (',', "jpg, gif, jpeg, png ");
// Set the nearby Upload Directory
$ Upload-> savePath =
"./Tpl/default/Public/image/"; // note that the directory is the relative path of the entry file
// You need to generate a thumbnail, which is only valid for image files.
// $ Upload-> thumb =
True;
// Set the path of the referenced image library package
// $ Upload-> imageClassPath =
'Org. Net. image ';
// Set the file suffix of the thumbnail to be generated
// $ Upload-> thumbPrefix
='M _, s _';
// Generate two thumbnails
// Set the maximum width of the thumbnail.
// $ Upload-> thumbMaxWidth
=
'000000 ′;
// Set the maximum height of the thumbnail.
// $ Upload-> thumbMaxHeight
= '000000 ′;
// Set file Upload rules
$ Upload-> saveRule =
Uniqid;
// Delete the source image
$ Upload-> thumbRemoveOrigin =
True;
If (! $ Upload-> upload ()){
// Capture Upload exceptions
$ This-> error ($ upload-> getErrorMsg ());
} Else {
// Obtain the information of the uploaded file
$ Info =
$ Upload-> getUploadFileInfo ();
$ This->
Success ("uploaded successfully ");
}
}
}
?>
2. create an index.html template in the indexfolder of default. the code is as follows:
<Title> New Document
Content = "EditPlus">
Content = "">
Enctype = "multipart/form-data">
</Form>
</Html>