Home > php教程 > php手册 > body text

Thinkphp3.2 practice of generating multiple thumbnails

WBOY
Release: 2016-10-09 08:32:18
Original
1228 people have browsed it

tp3.2 uses the thumb method to generate multiple thumbnails
$upload = new ThinkUpload(); // Instantiate the upload class<br>          $upload->maxSize                                                                                                                                       $ Upload-& GT; Exts = Array ('jpg', 'gif', 'png', 'jpeg') "./Public/Admin/Uploads/"; //Set the attachment upload directory//Upload files<br> $upload ->autoSub = true;<br>          $upload ->subName = array('date','Ymd');<br> //Set upload file rules<br>            $upload->saveRule                                                                                                                                $info = $upload->uploadOne($_FILES['photo']);<br>            if(!$info) {<br>                             // Upload error message <br>                   $this->error($upload->getError());<br>            }else {<br>                                                                                                                                                           // Uploaded successfully, obtained the uploaded file information <br>               $img = $info['savepath'] . $info['savename'];<br>              $image = new ThinkImage();<br>              $BinImg = $upload->rootPath . "$img"; // Get the absolute path of the original image <br>               $image->open($BinImg); // Open the original image<br>                               // Add watermark <br>                               // $image ->water($upload->rootPath."logo.png")-> save($upload ->rootPath.$img);<br>                              // Generate a <br> // $image ->thumb(278,206,2); // Set width, height and thumbnail type<br> <br>                       // Set thumbnail width, height, prefix <br>               $thumb = array(<br>                                                                             array('w'                                                 array('w'                                                                                                                                                                     2 = & gt; Array ('w' = & gt; 178, 'h' = & gt; 106, 'n' = & gt; '178x106 _') <br> );<br> foreach ($thumb as $k => $v){<br>                    $image->thumb($v['w'],$v['h'], 2); // Set width, height and thumbnail type <br>                                                                                                                                                                           $smallimg[$k]= $info['savepath'] . "$v[n]" . $info['savename'];<br> <br>                      $image->save($upload->rootPath . $smallimg[$k]);<br>                $_POST['small'.$k] = $smallimg[$k];<br>             }<br>             $_POST['goods_img'] = $img;<br>          <br>         }<br>         var_dump($_POST);exit;

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!