當前位置:首頁 » 編程語言 » php獲取圖片路徑

php獲取圖片路徑

發布時間: 2025-03-22 14:40:53

A. php怎麼讀取php所在文件夾下的圖片和mp3文件,並且顯示出來

顯示本文件夾下的A.JPG的語句:

echo"<imgsrc='a.jpg'/>";

可能你已經明白了,其實PHP輸出的是HTML代碼,PHP無需具體讀取文件內容,也無法在客戶的瀏覽器上繪圖,這一切只有交給瀏覽器去實現。

B. 用PHP獲取鏈接及圖片路徑的方法

<?php

$str="Thisisatest.Thisisatest.Thisisa<ahref=http://link1.com><imgsrc=http://img1.jpg/></a>test.Thisisatest.Thisisatest. ".
"Thisisatest.Thisisatest.<ahref=http://link2.com><imgsrc=http://img2.jpg/></a>Thisisatest.Thisisatest.Thisisatest. ".
"<ahref=http://link3.com><imgsrc=http://img3.jpg/></a>";

$regex='/<as+href=(.*)s*><imgs+src=(.*)s*/></a>/';
$output=array();

if(preg_match_all($regex,$str,$matches)!==false){
if(isset($matches[1])&&isset($matches[2])){
$links=$matches[1];
$imgs=$matches[2];

foreach($linksas$key=>$link){
$img=isset($imgs[$key])?$imgs[$key]:'';
$output[]="<ahref="{$link}"><imgsrc="{$img}"/></a>";
}
}
}

var_mp($output);

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

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

D. PHP怎麼上傳圖片路徑,怎麼獲取圖片路徑

$filePath 應該是上傳的臨時文件吧,然後將$filePath,這個文件移動到 $uploadPath,$uploadPath,應該就 你已經上傳的圖片的路徑!包含圖片文件的名稱。

E. php中如何讓圖片顯示出來,現在可以從資料庫中讀出圖片路徑

$conn=mysql_connect("localhost","root","");//ip用戶名密碼
mysql_select_db("sitecms",$conn);//資料庫名
mysql_query("setnames'utf8'");//utf-8格式
$sql="selecturlfromlinkwherelid=3";
$result=mysql_query($sql,$conn);
while($row=mysql_fetch_array($result)){
echo"<imgsrc='".$row['url']."'/>";
}

F. 求php中正則表達式從html代碼中獲取圖片路徑

<?php
$test = '<p>444<img height="768" width="1024" alt="" src="/uploadfiles/28/Tree.jpg" /></p>
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/sf/Tree.jpg" /></p>
fsdafasdfasdfasdf
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/28/elm.jpg" /></p>

sdfasdfasdf<p>
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/28/maple.jpg" /></p>

sdf32414撒旦發是否
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/40/Tree.jpg" /></p>';

preg_match_all("/<p>.*src=\"([^^]*?)\".*<\/p>/i",$test,$match);
print_r($match[1]);
?>

這樣應該可以,我試的多行的,中間還夾雜一些字元,沒什麼問題,呵呵

G. php讀取圖片的路徑

  1. 你的代碼是遍歷$dir文件夾下面的文件,然後輸出成<img src=""/>,訪問伺服器上的圖片一般是網址+具體路徑,例如:localhost/public/logo.jpg,是指訪問網址根目錄下的public/logo.jpg文件,對應你這里的就是htdocs/public/logo.jpg

  2. 圖片的顯示大小可以設置img的width和heigth屬性,位置可以設置相應的css值,例如<img src="/public/logo.jpg" width="100px" heigth="100px" style="display:block;margin:0 auto">

熱點內容
java模擬atm 發布:2025-03-22 22:10:46 瀏覽:239
演算法設計與優化 發布:2025-03-22 22:08:03 瀏覽:901
安卓車載怎麼調低音 發布:2025-03-22 22:03:18 瀏覽:37
刷卡機簽到密碼什麼 發布:2025-03-22 21:53:44 瀏覽:514
面試故事腳本 發布:2025-03-22 21:52:12 瀏覽:44
linux開啟網路 發布:2025-03-22 21:51:03 瀏覽:981
安卓手機哪個手機有carplay 發布:2025-03-22 21:43:34 瀏覽:862
密碼應該設八個字元是什麼意思 發布:2025-03-22 21:24:47 瀏覽:262
安卓耳機怎麼插上沒反應 發布:2025-03-22 21:16:42 瀏覽:845
java課程項目培訓 發布:2025-03-22 20:57:43 瀏覽:174