導航:首頁 > 編程語言 > 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圖片路徑資料庫中相關的資料

熱點內容
重慶伺服器租用哪裡有雲伺服器 瀏覽:453
土星模擬器文件夾 瀏覽:902
文件夾文件袋文件盒 瀏覽:695
雲伺服器打開f8指令 瀏覽:243
盈透證券加密幣 瀏覽:72
阿里雲伺服器初始密碼怎麼修改 瀏覽:266
伺服器怎麼設定公用網路 瀏覽:99
程序員自己嘗尿檢測出糖尿病 瀏覽:593
列印添加pdf 瀏覽:932
蘋果解壓專家賬號 瀏覽:842
度曉曉app為什麼關閑 瀏覽:228
net文件是偽編解碼嗎 瀏覽:149
伴隨矩陣的matlab編程 瀏覽:63
單片機和h橋是什麼意思 瀏覽:314
51單片機光控設計論文 瀏覽:653
渦旋式壓縮機無油 瀏覽:731
企業網搭建及應用pdf 瀏覽:744
symanteclinux 瀏覽:879
程序員朋友化妝改造 瀏覽:493
應用被加密但不知道密碼 瀏覽:586