導航:首頁 > 編程語言 > php圖片路徑資料庫中

php圖片路徑資料庫中

發布時間:2025-02-13 06:52:41

1. php怎麼把資料庫中圖片的路徑轉化為圖片呢

先用php把資料庫中的圖片路徑讀取出來,然後把這個路徑嵌入到img元素的src中,就相當於把圖片的路徑轉化為圖片了。

2. php 一個圖片我想設置許可權,讓有許可權的用戶可以打開。 怎樣防止用戶找到這個圖片的絕對地址後直拉打開

classimgdata{
public$imgsrc;
public$imgdata;
public$imgform;
publicfunctiongetdir($source){
$this->imgsrc=$source;
}
publicfunctionimg2data(){
$this->_imgfrom($this->imgsrc);
return$this->imgdata=fread(fopen($this->imgsrc,'rb'),filesize($this->imgsrc));
}
publicfunctiondata2img(){
header("content-type:$this->imgform");
echo$this->imgdata;
//echo$this->imgform;
//imagecreatefromstring($this->imgdata);
}
publicfunction_imgfrom($imgsrc){
$info=getimagesize($imgsrc);
//var_mp($info);
return$this->imgform=$info['mime'];
}
}
$n=newimgdata;
$n->getdir("1.jpg");//圖片路徑,一般存儲在資料庫里,用戶無法獲取真實路徑,可根據圖片ID來獲取
$n->img2data();
$n->data2img();

這段代碼是讀取圖片,然後直接輸出給瀏覽器,在讀取和輸出之前,進行用戶許可權判斷。

3. 怎樣把圖片插入到資料庫中 php

保存圖片到資料庫做什麼?保存到本地使用起來也方便,真要保存通過base64字元串保存。

<?php
header('Content-type:text/html;charset=utf-8');
//讀取圖片文件,轉換成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輸入到資料庫

//保存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;
}

}
?>
<imgsrc="<?phpecho$base64_image_content;?>"/>
閱讀全文

與php圖片路徑資料庫中相關的資料

熱點內容
雲引擎雲伺服器 瀏覽:903
解壓視頻聲控吃冰義大利 瀏覽:401
渦旋壓縮機動渦盤 瀏覽:875
手機郵件發文件夾 瀏覽:446
魔獸世界懷舊服tbc薩滿宏命令 瀏覽:546
linuxsvn手冊 瀏覽:264
程序員圖鑒 瀏覽:537
東營程序員 瀏覽:714
發票上傳參數沒置伺服器地址 瀏覽:43
程序員網上接單能掙多少錢 瀏覽:179
稀有傳奇手游源碼 瀏覽:551
u盤里的cd驅動加密是什麼 瀏覽:419
遺傳演算法編碼長度 瀏覽:978
pe裝伺服器需要注意什麼 瀏覽:324
foreach計數php 瀏覽:529
php自連接 瀏覽:300
程序員被噴了怎麼辦 瀏覽:713
android消息數 瀏覽:265
為什麼在伺服器里輸不了指令 瀏覽:33
程序員那麼可愛前女友劇情介紹 瀏覽:106