php图片流显示
<?php
$dir = "./images/"; //要获取的目录
echo "********** 获取目录下所有文件和文件夹 ***********<hr/>";
//先判断指定的路径是不是一个文件夹
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh))!= false){
//文件名的全路径 包含文件名
$filePath = $dir.$file;
echo "<img src='".$filePath."'/>";
}
closedir($dh);
}
}
?>
‘贰’ php如何让数据库中的图片在网页首页滚动显示
可以用无缝图片滚动效果 如:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
* { margin: 0; padding: 0;}
body{ background-color:#1B1B1B}
#div1{ width: 800px; height: 150px; position: relative; margin: 100px auto;overflow: hidden;}
#div1 ul { width: 800px; height: 150px; position: relative; }
#div1 ul li { height: 150px; float: left; list-style: none; padding-right:20px;}
#div1 ul li img { width: 200px; height: 150px; display: inline-block;}
a{ color: #B4B4B4; }
</style>
<script type="text/javascript">
window.onload=function(){
var odiv = document.getElementById('div1');
var oul = odiv.getElementsByTagName('ul')[0];
var ali = oul.getElementsByTagName('li');
var spa = -2;
oul.innerHTML=oul.innerHTML+oul.innerHTML;
oul.style.width=ali[0].offsetWidth*ali.length+'px';
function move(){
if(oul.offsetLeft<-oul.offsetWidth/2){
oul.style.left='0';
}
if(oul.offsetLeft>0){
oul.style.left=-oul.offsetWidth/2+'px'
}
oul.style.left=oul.offsetLeft+spa+'px';
}
var timer = setInterval(move,30)
odiv.onmousemove=function(){clearInterval(timer);}
odiv.onmouseout=function(){timer = setInterval(move,30)};
document.getElementsByTagName('a')[0].onclick = function(){
spa=-2;
}
document.getElementsByTagName('a')[1].onclick = function(){
spa=2;
}
}
</script>
</head>
<body>
<a href="#" style=" display: block; margin:0 auto; width: 50px;">向左走</a>
<a href="#" style=" display: block; margin:0 auto; width: 50px;">向右走</a>
<div id="div1">
<ul>
<li><img src="img/1.jpg"/></li>
<li><img src="img/2.jpg"/></li>
<li><img src="img/3.jpg"/></li>
<li><img src="img/4.jpg"/></li>
</ul>
</div>
</body>
</html>
‘叁’ 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']."'/>";
}
‘肆’ php中如何调用数据库中的图片并且显示到页面
php是采用二进制形式存储图片及读取显示的,首先通过代码创建数据表,然后上传图片服务器再通过浏览器显示,具体编程代码举例:
1、首先需要创建数据表,具体代码如下图所示。