Upload image -- save and display image -- JS get thumbnail parameter -- submit location parameter -- image scaling save class process image -- save captured image -- Update database -- jump
Upload image -- save and display image -- JS get thumbnail parameter -- submit location parameter -- image scaling save class process image -- save captured image -- Update database -- jump
Author: Yang xinqi
Original link:
A big brother of the TP Forum joined me tonight and said that he also encountered this problem! Think about the fact that many things have been encountered. Should we share them? In fact, many of my own things come from other people, and they are used by the network! It can be improved only when you share more information!
Implementation Method
Upload image -- save and display image -- JS get thumbnail parameter -- submit location parameter -- image scaling save class process image -- save captured image -- Update database -- jump
Several images
The following are examples
Main Implementation Code
The Code is as follows:
Public function cutimg ()
{
$ Result = $ this-> upload ('temp ');
If (! Is_array ($ result ))
{
$ This-> redirect ('index ');
}
Else
{
$ This-> assign ('imgurl', '/'. C ('attachdir'). '/temp/'. $ result [0] ['savename']);
$ This-> assign ('imgname', $ result [0] ['savename']);
$ This-> display ();
}
}
The Code is as follows:
Public function setavatar ()
{
If (! Empty ($ _ REQUEST ['cut _ pos'])
{
// Import ('org. Util. ImageResize ');
Require ('imageresize. class. php ');
$ Imgresize = new ImageResize ();
// Use the full path
$ Url = C ('attachdir'). '/temp/'. trim ($ _ POST ['imgname']);
$ Imgresize-> load ($ url );
Dump ($ url );
$ Posary = explode (',', $ _ REQUEST ['cut _ pos']);
Foreach ($ posary as $ k => $ v)
$ Posary [$ k] = intval ($ v );
If ($ posary [2]> 0 & $ posary [3]> 0) $ imgresize-> resize ($ posary [2], $ posary [3]);
Dump ($ posary );
// Create filename rule
$ Uico = time (). '.jpg ';
Dump ($ uico );
$ Path = C ('Avatar ');
// Save 120*120 image
$ Imgresize-> cut (120,120, intval ($ posary [0]), intval ($ posary [1]);
$ Large = 'l _ '. $ uico;
$ Imgresize-> save ($ path. $ large );
Echo '';
// Update database
}
Else
{
// Error reporting
}
}
Source code: others to improve themselves, run the TP framework need to visit the http://www.thinkphp1.cn download, and then download the extension package, because the use of Upload class!