PHP代码如下(附说明):
1 public function add(){ 2 if(IS_POST){ 3 $goods = M("goods"); 4 $data = $_POST; 5 $data["on_time"] = date('Y-m-d H:s'); 7 $conf = array( 8 "rootPath" => "./app/upload/" 9 ); 10 $uploads = new upload($conf); 11 $info = $uploads -> uploadOne($_FILES["original_img"]); 14 $data["original_img"] = $info["savepath"].$info["savename"]; 16 $image = new Image(); 17 $big_img = $uploads ->rootPath.$info["savepath"].$info["savename"]; 19 $image ->open($big_img); 21 $image ->thumb(150,150,6); 23 $small_img = $uploads ->rootPath.$info["savepath"].'small_'.$info["savename"]; 24 $image ->save($small_img); 25 $data['keywords'] = $info["savepath"].'small_'.$info["savename"]; 26 $goods -> add($data); 27 $this -> redirect("zhanshi",array(),1,"添加成功"); 28 29 }
html视图代码(附说明):
1 <td><img src="{$Think.const.UPLOAD_PATH}{$vo.original_img}" height="60" width="60"></td> 2 <td><img src="{$Think.const.UPLOAD_PATH}{$vo.keywords}" height="40" width="40"></td>
路径常量代码(附说明):
1 define("UPLOAD_PATH","http://localhost/ThinkPHP/app/upload/");
基本效果展示: