龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php批量上传一[带预览]

时间:2012-12-24 21:59来源:未知 作者:admin 点击:
分享到:
代码如下: ?php require('inc/conn.php'); ? head head meta http-equiv=Content-Type c / title图片上传实现/title script language=javascript function preview(x){ if(!x || !x.value) return; var patn = /.jpg$|.jpeg$|.gif$/i; if(patn.te

代码如下:

<?php
require('inc/conn.php');
?>
<head>
<head>
<meta http-equiv="Content-Type" c />
<title>图片上传实现</title>
<script language="javascript">
function preview(x){
    if(!x || !x.value) return;
    var patn = /.jpg$|.jpeg$|.gif$/i;
    if(patn.test(x.value)){
        if(x.parentNode.nextSibling.firstChild){
            //看看是不是已经添加了图片标签,如果添加了就直接修改图片地址
            x.parentNode.nextSibling.firstChild.setAttribute('src','file://localhost/'+x.value);
        }else{
            //没添加就创建个咯,然后加入到当前节点的父节点的下一个节点 -_-
            var img = document.createElement('img');
            img.setAttribute('src','file://localhost/'+x.value);
            img.setAttribute('width',120);
            img.setAttribute('height',100);
            x.parentNode.nextSibling.appendChild(img);
            //parentNode  父节点
            //nextSibling 下个节点
            //appendChild 添加个子节点
                        return(x.value);
        }
    }else{
        alert('貌似你选的不是个图片的说!');
        x.value='';                            //本人不懂js,考来的,对不住各位了,也谢谢原作者!
    }
}
</script>
</head>
</head>
<body>


精彩图集

赞助商链接