日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
php圖片上到數(shù)據(jù)庫 php圖片上到數(shù)據(jù)庫怎么弄

php中如何將圖片儲存在數(shù)據(jù)庫里

兩種方法:

黃驊網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,黃驊網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為黃驊近1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個(gè)售后服務(wù)好的黃驊做網(wǎng)站的公司定做!

一:將圖片上傳至指定目錄,在數(shù)據(jù)庫中保存文件名和文件路徑。

二:將圖片文件讀入字符串,將字符串保存到數(shù)據(jù)庫,不推薦(沒那么長的字段長度支持)。

php圖片保存到數(shù)據(jù)庫

1.圖片轉(zhuǎn)換 將上傳的圖片讀取到一個(gè)字符串中,再用base64對數(shù)據(jù)進(jìn)行編碼 $img =base64_encode(file_get_contents($_FILES['file_head']['tmp...

2.顯示圖片 imgsrc="{$base64String}" 這樣就能把圖片顯示出來了

PHP實(shí)現(xiàn)上傳圖片到數(shù)據(jù)庫并顯示輸出的方法

本文實(shí)例講述了PHP實(shí)現(xiàn)上傳圖片到數(shù)據(jù)庫并顯示輸出的方法。分享給大家供大家參考,具體如下:

1.

創(chuàng)建數(shù)據(jù)表

CREATE

TABLE

ccs_image

(

id

int(4)

unsigned

NOT

NULL

auto_increment,

description

varchar(250)

default

NULL,

bin_data

longblob,

filename

varchar(50)

default

NULL,

filesize

varchar(50)

default

NULL,

filetype

varchar(50)

default

NULL,

PRIMARY

KEY

(id)

)engine=myisam

DEFAULT

charset=utf8

2.

用于上傳圖片到服務(wù)器的頁面

upimage.html

!doctype

html

html

lang="en"

head

meta

charset="UTF-8"

meta

name="viewport"

content="width=device-width,

user-scalable=no,

initial-scale=1.0,

maximum-scale=1.0,

minimum-scale=1.0"

meta

http-equiv="X-UA-Compatible"

content="ie=edge"

style

type="text/css"

*{margin:

1%}

/style

titleDocument/title

/head

body

form

method="post"

action="upimage.php"

enctype="multipart/form-data"

描述:

input

type="text"

name="form_description"

size="40"

input

type="hidden"

name="MAX_FILE_SIZE"

value="1000000"

br

上傳文件到數(shù)據(jù)庫:

input

type="file"

name="form_data"

size="40"br

input

type="submit"

name="submit"

value="submit"

/form

/body

/html

3.

處理圖片上傳的php

upimage.php

?php

if

(isset($_POST['submit']))

{

$form_description

=

$_POST['form_description'];

$form_data_name

=

$_FILES['form_data']['name'];

$form_data_size

=

$_FILES['form_data']['size'];

$form_data_type

=

$_FILES['form_data']['type'];

$form_data

=

$_FILES['form_data']['tmp_name'];

$dsn

=

'mysql:dbname=test;host=localhost';

$pdo

=

new

PDO($dsn,

'root',

'root');

$data

=

addslashes(fread(fopen($form_data,

"r"),

filesize($form_data)));

//echo

"mysqlPicture=".$data;

$result

=

$pdo-query("INSERT

INTO

ccs_image

(description,bin_data,filename,filesize,filetype)

VALUES

('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");

if

($result)

{

echo

"圖片已存儲到數(shù)據(jù)庫";

}

else

{

echo

"請求失敗,請重試";

注:圖片是以二進(jìn)制blob形式存進(jìn)數(shù)據(jù)庫的,像這樣

4.

顯示圖片的php

getimage.php

?php

$id

=2;//

$_GET['id'];

為簡潔,直接將id寫上了,正常應(yīng)該是通過用戶填入的id獲取的

$dsn='mysql:dbname=test;host=localhost';

$pdo=new

PDO($dsn,'root','root');

$query

=

"select

bin_data,filetype

from

ccs_image

where

id=2";

$result

=

$pdo-query($query);

$result=$result-fetchAll(2);

//

var_dump($result);

$data

=

$result[0]['bin_data'];

$type

=

$result[0]['filetype'];

Header(

"Content-type:

$type");

echo

$data;

到瀏覽器查看已經(jīng)上傳的圖片,看是否可以顯示

是沒有問題的,證明圖片已經(jīng)以二進(jìn)制的形式存儲到數(shù)據(jù)庫了

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《php+mysqli數(shù)據(jù)庫程序設(shè)計(jì)技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》

希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:php實(shí)現(xiàn)上傳圖片保存到數(shù)據(jù)庫的方法php上傳圖片存入數(shù)據(jù)庫示例分享php上傳圖片到指定位置路徑保存到數(shù)據(jù)庫的具體實(shí)現(xiàn)php中如何將圖片儲存在數(shù)據(jù)庫里php下將圖片以二進(jìn)制存入mysql數(shù)據(jù)庫中并顯示的實(shí)現(xiàn)代碼php

從數(shù)據(jù)庫提取二進(jìn)制圖片的處理代碼php將圖片保存入mysql數(shù)據(jù)庫失敗的解決方法php將圖片文件轉(zhuǎn)換成二進(jìn)制輸出的方法php圖片的二進(jìn)制轉(zhuǎn)換實(shí)現(xiàn)方法

怎樣把圖片插入到數(shù)據(jù)庫中 php

保存圖片到數(shù)據(jù)庫做什么?保存到本地使用起來也方便,真要保存通過base64字符串保存。

?php

header('Content-type:text/html;charset=utf-8');

//讀取圖片文件,轉(zhuǎn)換成base64編碼格式

$image_file?=?'./image123.jpg';

$image_info?=?getimagesize($image_file);

$base64_image_content?=?"data:{$image_info['mime']};base64,"?.?chunk_split(base64_encode(file_get_contents($image_file)));

//?$base64_image_content?輸入到數(shù)據(jù)庫

//保存base64字符串為圖片

//匹配出圖片的格式

if?(preg_match('/^(data:\s*image\/(\w+);base64,)/',?$base64_image_content,?$result)){

$type?=?$result[2];

$new_file?=?"./test.{$type}";

if?(file_put_contents($new_file,?base64_decode(str_replace($result[1],?'',?$base64_image_content)))){

echo?'新文件保存成功:',?$new_file;

}

}

?

img?src="?php?echo?$base64_image_content;?"?/


文章標(biāo)題:php圖片上到數(shù)據(jù)庫 php圖片上到數(shù)據(jù)庫怎么弄
轉(zhuǎn)載來于:http://www.dlmjj.cn/article/ddeopgj.html