首頁 > php框架 > ThinkPHP > 主體

thinkphp5圖片檔案上傳並在頁面展示出來

爆肝混世大魔王-流笙 第五人格服务
發布: 2021-03-15 09:02:30
原創
148 人瀏覽過

圖片上傳

圖片:< br>


 

 

#namespace app\ index\ controller;

use think\ Controller;

#use app\ index\ model\ Image as ImageModel;

#use think\ Request;

class Image extends controller {

public

function index() {

return view( 'index/sc' );

#}

public

function image() {

// echo "圖片上傳";

return view( 'Image/image' );

}

// protected $resultSetType = 'collection';

public

function upload() {

// 取得表單上傳檔案例如上傳了001.jpg

$file = request()->file( 'image' );

// 移動到框架應用根目錄/uploads/ 目錄下

$info = $file->move( '../public' );

//取得圖片路徑

$img = $info->getSaveName();

//取得前台資料

$data = input( 'post.' );

#//將圖片路徑拼接陣列

$c = $data [ 'image' ] = $img;

//入庫

$b = new ImageModel();

$b->images = $c;

if ( $b->save() ) {

return '新增成功';

} else {

return '新增失敗';

}

}

public

function list() {

$b = new ImageModel();//連接資料庫

$c= "SELECT * FROM `image`  \n"//查詢資料sql語句

    . "ORDER BY `image`.`images` ASC";//think原生查詢方法

$res = $b->query($c);

$this->assign( [//把查出來的資料渲染給頁面

'a' => $res 

] );

return $this->fetch( 'index/cs' );//渲染給index模組的cs頁面

}

}

#

顯示圖片

{volist name="a" id="a" offset="0" length="a"}

{/volist}

namespace app\index\model;

class Image extends \think\Model

#{

    // 設定目前模型對應的完整資料表名稱

    protected $table = 'image';

    

    // 設定目前模型的資料庫連線

    protected $connection = [

        // 資料庫類型

        'type'        

        'hostname'    => '127.0.0.1',

        // 資料庫名稱

       'database'  // 資料庫名稱

       'database』使用者名稱

        'username'    => 'image',

        // 資料庫密碼

        'password'  // 資料庫密碼

        'password'  // 資料庫密碼

        'password' // 資料庫編碼預設為utf8

        'charset'     => 'utf8',

        // 資料庫字號

#), fi        // 

        // 數據庫調試模式

        'debug'       => true,

    ];

}

以上是thinkphp5圖片檔案上傳並在頁面展示出來的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
1
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!