您正在使用 IPV4 [18.97.14.86] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
[公益]保护绿色环境,构建和谐社会      

【腾讯云】2核2G云服务器新老同享 99元/年,续费同价,云服务器3年机/5年机限时抢购,低至 2.5折      
[公益] 地球是我家,绿化靠大家      
2025年 春 节 011
2025年 高 考 140
2025年 春 节 011
2026年 元 旦 348
 
您现在的位置:首页 >> PHP >> 内容
本类新增
本类热门
php实现文件预览功能
内容摘要: 1.yulan.php!DOCTYPEhtmlPUBLIC'-//W3C//DTDXHTML1.0Transitional//EN''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'htmlxmlns='http://www.w3.org/1999/xhtml'headmetahttp-equi......
1.yulan.php

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<head>

<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>

<title>无标题文档</title>

<styletype="text/css">

#yl{width:200px;height:300px;background-image:url(images/timg1.jpg);background-size:200px300px;}

#file{width:200px;height:300px;float:left;opacity:0;}

</style>

</head>

<body>

<formid="sc"action="ylchuli.php"method="post"enctype="multipart/form-data"target="shangchuan">

<inputtype="hidden"name="tp"value=""id="tp"/>

<divid="yl">

<inputtype="file"name="file"id="file"onchange="document.getElementById('sc').submit()"/>

</div>

</form>

<iframestyle="display:none"name="shangchuan"id="shangchuan">

</iframe>

</body>

<scripttype="text/javascript">

//回调函数,调用该方法传一个文件路径,改变背景图

functionshowimg(url)

{

vardiv=document.getElementById("yl");

div.style.backgroundImage="url("+url+")";

document.getElementById("tp").value=url;

}

</script>

</html>

2.ylchuli.php

<?php

if($_FILES["file"]["error"])

{

echo$_FILES["file"]["error"];

}

else

{

if(($_FILES["file"]["type"]=="image/jpeg"||$_FILES["file"]["type"]=="image/png")&&$_FILES["file"]["size"]<1024000)

{

$fname="./images/".date("YmdHis").$_FILES["file"]["name"];

$filename=iconv("UTF-8","gb2312",$fname);

if(file_exists($filename))

{

echo"<script>alert('该文件已存在!');</script>";

}

else

{

move_uploaded_file($_FILES["file"]["tmp_name"],$filename);

$delurl=iconv("UTF-8","gb2312",$_POST["tp"]);

unlink($delurl);//删除文件

echo"<script>parent.showimg('{$fname}');</script>";

}

}

}

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:PHP获取用户的浏览器与操作系统信息的代码

 

下一篇:php实现TCP端口检测的方法

发布日期:2023/9/26
手机扫二维码直达本页
发布时间:16:00:35
点  击:11
录  入:齐天大圣
相关文章
Baidu
YiJiaCMS 7.5.5 build241121(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,创宇云安全提供加速防护
运行时间载入中.....
知道创宇云安全