當前位置:首頁 » 編程語言 » 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">

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:633
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:362
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:78
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:303
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:789
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:339
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:206
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:806
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:360
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:586