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

熱點內容
資料庫查詢系統源碼 瀏覽:612
php5314 瀏覽:352
完美國際安裝到哪個文件夾 瀏覽:664
什麼app可以掃一掃做題 瀏覽:535
程序員編碼論壇 瀏覽:921
淘點是什麼app 瀏覽:656
中國高等植物pdf 瀏覽:451
51單片機時間 瀏覽:179
後台如何獲取伺服器ip 瀏覽:261
單片機流水燈程序c語言 瀏覽:230
程序員第二職業掙錢 瀏覽:237
運行里怎麼輸入伺服器路徑 瀏覽:835
pythonstepwise 瀏覽:505
劉一男詞彙速記指南pdf 瀏覽:59
php認證級別 瀏覽:364
方舟編譯啥時候推送 瀏覽:1007
php手機驗證碼生成 瀏覽:672
哲學思維pdf 瀏覽:13
凌達壓縮機有限公司招聘 瀏覽:531
weblogic命令部署 瀏覽:33