1.图片上传一开始页面
/*
打开window oper
*/
function dopic(url,height,width)
{
return window.open(url,'图片上传管理',"height="+height+",width="+height+",top=50,left=100,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
//上传图片JS获取图片信息
function dianji(v)
{
document.getElementById('pic').value=v;
document.getElementById("show").innerHTML='';
}
2.upload.php<?php
session_start();
if(!isset($_SESSION['username'])){echo "";}
?>
#mydiv{ width:460px; height:360px;}
ul{
width:450px;}
li{
list-style-type:none; float:left; padding:4px;
}
li img{
cursor:pointer; border:2px #CCC groove}
li img:hover{
cursor:pointer; border:2px #F00 groove}
.del{
padding-left:30px;}
.del a{
text-decoration:none;
color:#999;
font-size:13px;}
.del a:hover{
text-align:center;
text-decoration:underline;
background:#F00}
#changpage{
text-align:center; margin-top:10px;}
#changpage a{
color:#000; text-decoration:none}
#changpage a:hover{
color:#F00; text-decoration:underline}
#up{
text-align:center;
background:#CCC;
margin-top:10px;}
.top{
color:#F00;
font-size:12px;
font-weight:bold;}
function qd(v)
{
window.opener.dianji(v);
window.close();
}
if($_GET['del'])
{
$dir = 'upload/';
if($fileopen = opendir($dir))
{
@unlink($dir.$_GET['del']);
}
}
?>
$resPath = 'upload/';
if ($dh = opendir($resPath))
{
while (($file = readdir($dh)) !== false)
{
if($file !='.' and $file !='..' and end(explode('.',$file))!='db')
{
echo "
}
}
closedir($dh);
}
?>
var obj,j;
var page=0;
var nowPage=0;//当前页
var listNum=6;//每页显示
- 数
var PagesLen;//总页数
var PageNum=4;//分页链接接数(5个)
οnlοad=function(){
obj=document.getElementById("mydiv").getElementsByTagName("li");
j=obj.length
PagesLen=Math.ceil(j/listNum);
upPage(0)
}
function upPage(p){
nowPage=p
//内容变换
for (var i=0;i
obj[i].style.display="none"
}
for (var i=p*listNum;i
if(obj[i])obj[i].style.display="block"
}
//分页链接变换
strS='首页 '
var PageNum_2=PageNum%2==0?Math.ceil(PageNum/2)+1:Math.ceil(PageNum/2)
var PageNum_3=PageNum%2==0?Math.ceil(PageNum/2):Math.ceil(PageNum/2)+1
var strC="",startPage,endPage;
if (PageNum>=PagesLen) {startPage=0;endPage=PagesLen-1}
else if (nowPagePageNum?PageNum:PagesLen-1}//首页
else {startPage=nowPage+PageNum_3>=PagesLen?PagesLen-PageNum-1: nowPage-PageNum_2+1;var t=startPage+PageNum;endPage=t>PagesLen?PagesLen-1:t}
for (var i=startPage;i<=endPage;i++){
if (i==nowPage)strC+=''+(i+1)+' '
else strC+=''+(i+1)+' '
}
strE=' 尾页 '
strE2=nowPage+1+"/"+PagesLen+"页"+" 共"+j+"条"
document.getElementById("changpage").innerHTML=strS+strC+strE+strE2
}
3.upload_send.php<?php
session_start();
if(!isset($_SESSION['username'])){echo "";}
if($_FILES['myfile']){
function uploadFile($file)
{ //上传路径
$destinationPath = "upload/";
if (!file_exists($destinationPath)){mkdir($destinationPath,0777);}
//命名后面部份随机;
$str = '0123456789abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';
$a = strlen($str);
for($i=1;$i<6;$i++)
{
$a = rand('0',$a-1);
$string.=substr($str,$a,1);
}
//分割原来图片实名
$name = end(explode('.',iconv('utf-8','gb2312',basename($file['name']))));
//重命名,实名iconv('utf-8','gb2312',basename($file['name']))
$fileName = date('YmdHis').$string.".".$name;
if (@move_uploaded_file($file['tmp_name'],$destinationPath.$fileName)){
return iconv('gb2312','utf-8',$fileName);
}
}
function readFromFile($target_path)
//读取文件内容
{
$file = fopen($target_path,'rb') or die("unable to open file");
$fileContent = '';
while(!feof($file)){
$str = fgets($file);
$fileContent .= $str;
}fclose($file);
return $fileContent;}
if($_FILES['myfile']['name'] == ''){echo "";exit();}
$file = $_FILES['myfile'];
$type = $_FILES['myfile']['type'];
$size = $_FILES['myfile']['size'];
if($size/1000 > 100){echo "";exit();}
if($type != "image/jpeg" || $type != "image/png" || $type != "image/gif")
{
echo "";
exit;
}
$pic = 'upload/';
$fileName = uploadFile($file);
$result = readFromFile($pic.$fileName);
$img = "";
echo "";
}
本文原创发布php中文网,转载请注明出处,感谢您的尊重!