图片上传 管理php,图片上传管理

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='%5C%22'';

}

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 "

.%24resPath.%24file. 【删除】";

}

}

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 = ".%24pic.%24fileName.";

echo "";

}

e39872a53122c14576dd51ffff22601b.png

d88ff83f232bf69e68cf63b6ef29745c.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值