php获取图片路径
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读取图片的路径
你的代码是遍历$dir文件夹下面的文件,然后输出成<img src=""/>,访问服务器上的图片一般是网址+具体路径,例如:localhost/public/logo.jpg,是指访问网址根目录下的public/logo.jpg文件,对应你这里的就是htdocs/public/logo.jpg
图片的显示大小可以设置img的width和heigth属性,位置可以设置相应的css值,例如<img src="/public/logo.jpg" width="100px" heigth="100px" style="display:block;margin:0 auto">