thinkphp5 image files are uploaded and displayed on the page
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 "image upload";
return view( 'Image/image' );
}
// protected $resultSetType = 'collection';
public
function upload() {
// Get form upload file e.g. upload 001.jpg
$file = request()->file( 'image' );
// Move to the framework application root directory /uploads/ directory
$info = $file->move( '../public' );
//Get the image path
$img = $info->getSaveName();
//Get the foreground data
$data = input( 'post.' );
//Splice the image path into the array
$c = $data [ 'image' ] = $img;
//Into the library
$b = new ImageModel();
$b->images = $c;
if ( $b->save() ) {
return 'Add successfully';
} else {
return 'Add failed';
}
}
public
function list() {
$b = new ImageModel();//Connect to the database
$c= "SELECT * FROM `image` \n"//Query data sql statement
. "ORDER BY `image`.`images` ASC";//think native query Method
$res = $b->query($c);
$this->assign( [//Render the found data to the page
'a' => $res
] );
return $this->fetch( 'index/cs' );//The cs page rendered to the index module
}
}
{volist name="a" id="a" offset="0" length="a"}
{/volist}
namespace app\index\model;
class Image extends \think\Model
{
// Set the complete data table name corresponding to the current model
protected $table = 'image';
// Set the database connection of the current model
protected $connection = [
// Database type
'type' => 'mysql',
// Server address
’ ’ ’ ’ ’ s ’ ’ s ’ ’ ’ ’ ’ ’ ’ ’ s ’ ’ ’ s ‐ ‐ ‐ to 127.0.0.1',
## Username 'username' => 'image', use with use using out out through through through off ‐ ‐ ‐‐ ‐‐‐ ` to // Database coding The default uses UTF8 # 'Charset' = & GT; 'UTF8',## // database table prefix
'prefix' = & gt; 'Images'
// Database debugging mode
'debug' => true,
];
}
The above is the detailed content of thinkphp5 image files are uploaded and displayed on the page. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics









