<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>临时文件中心</title>
</head>

<body>
     <?php
	 error_reporting(0); 

	 $Filepath="../";	
	// @mkdir($Filepath."done/") ;
//// 获取当前目录
//echo "<hr>当前目录<br>";
//echo realpath("."). "<br>";  
//echo getcwd() . "<br>";  
//
//// 获取上级目录
//echo "<hr>上级目录<br>";
//echo realpath(".."). "<br>";  
//
//// 获取网站根目录
//echo "<hr>网站根目<br>";
//echo $_SERVER['DOCUMENT_ROOT'];
//
//// 获取目录信息
//echo "<hr>目录信息<br>";
//$path_parts = pathinfo(__FILE__);  
//echo $path_parts["dirname"] . "<br>"; 
//echo $path_parts["basename"] . "<br>"; 
//echo $path_parts["extension"] . "<br><hr>"; 
//echo dirname(__FILE__);

function dirsize($dir) {
@$dh = opendir($dir);
$size = 0;
while ($file = @readdir($dh)) {
if ($file != "." and $file != "..") {
$path = $dir."/".$file;
if (is_dir($path)) {
$size += dirsize($path);
} elseif (is_file($path)) {
$size += filesize($path);
}
}
}
@closedir($dh);
return $size;
}
?>
     <table cellspacing="1" cellpadding="5" width="100%" border="0">
       <tbody>
         <tr bgcolor="#99ccff">
           <td><b class="title"> 文件上传 <a href="../"> </a></b>
           	<input type="button" value="刷新" onclick="window.parent.frames[2].location.reload()" />  </td>
         </tr>
         <tr>
           <td bgcolor="#f2f8ff" height="186">&nbsp;
             <?php
				
				//$Filepath="../img-shopimg/";							//上载文件存放路径
				$Filepath="./Photo/";							//上载文件存放路径

				//up file;
				if($_POST['UploadAction']){
					//$upfile=$_FILES['Upfile']['tmp_name']; 
					//$upfilename=$_FILES['Upfile']['name']; 
					//copy($upfile,$upfilename); 
					//echo"上传成功! ";
					
					If(($_FILES['Upfile'] != "none")&& ($_FILES['Upfile'] != "")) 
					{ 
						$FileName=$Filepath.$_FILES['Upfile']['name']; 
						if($_FILES['Upfile']['size'] <1024)						//上载文件大小 
							{$FileSize = (string)$_FILES['Upfile']['size'] . "字节";} 
						elseif($_FILES['Upfile']['size'] <(1024 * 1024)) 
						{$FileSize = number_format((double)($_FILES['Upfile']['size'] / 1024), 1) . " KB";} 
						else {$FileSize = number_format((double)($_FILES['Upfile']['size']/(1024*1024)),1)."MB";} 
						if(file_exists($FileName)) {
						echo "文件 $Upfile_name 已经存在！覆盖....";  
					    //if(unlink($FileName)){echo "删除 $del 成功";}
						}
							if(copy($_FILES['Upfile']['tmp_name'],$FileName)) 
							{unlink($_FILES['Upfile']['tmp_name']); 
							echo "<br><br>\n";	 	
							echo "文件 $Upfile_name 已上载成功！";
							echo "<br><br>\n";
							echo "文件位置：$FileName";
							echo "<br><br>\n";
							echo "文件大小：$FileSize";
							echo "<br><br>\n";
							}else {echo "文件 $Upfile_name 上载失败！"; } 
						 
				} else {echo "你没有选择任何文件上载！"; } 
				}
				//upfile end

?>
             <table width="100%" height="92" border="1" cellpadding="0" cellspacing="0" bordercolor="#CC6633" class="bg6"><div id="area" ondrop="drop1(event)" ondragover="allowDrop1(event)"></div>
<div id="preview"></div>
<div id="result"></div>

<style type="text/css">
#area {width:300px;height:160px;padding:10px;border:1px solid #aaaaaa;}
#result {width:300px;height:30px;padding:10px;border:1px solid #aaaaaa;}
</style>
<script type="text/javascript">
if(typeof(Worker)!=="undefined")
    {
        // 浏览器支持HTML5
	var i = 5;
	document.getElementById("area").innerHTML="将图片拖拽到此区域自动上传";
	document.getElementById("result").innerHTML="";
	function allowDrop1(ev)
	{
	ev.preventDefault();
	}
	function drop1(e) {
		e.preventDefault(); //取消默认浏览器拖拽效果
		var fileList = e.dataTransfer.files; //获取文件对象
		//检测是否是拖拽文件到页面的操作
		if (fileList.length == 0) {
			return false;
		}
		//检测文件是不是图片
		if (fileList[0].type.indexOf('image') === -1) {
			alert("您拖的不是图片！");
			return false;
		}
		//拖拉图片到浏览器，可以实现预览功能
		var img = window.webkitURL.createObjectURL(fileList[0]);
		var filename = fileList[0].name; //图片名称
		var filesize = Math.floor((fileList[0].size) / 1024);
		if (filesize > 5500) {
			alert("上传大小不能超过5.5M.");
			return false;
		}
		//setInterval(window.location.reload(),1000);
		var str = "<img src='" + img + "' width='100' height='80'><p>图片名称：" + filename + "</p><p>大小：" + filesize + "KB</p>";
		document.getElementById("area").innerHTML=str;
		//alert("上传" + filename );
		setInterval(a0,1000);
		setInterval(al,5000);

		//上传
		xhr = new XMLHttpRequest();
		xhr.open("post", "upload.php", true);
		xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
		
		var fd = new FormData();
		fd.append('mypic', fileList[0]);
		
		xhr.send(fd);
		document.getElementById("result").innerHTML="上传" + filename + " 成功！";
	}
	function a0(){
		i=i-1;
		document.getElementById("result").innerHTML=i + "秒后刷新";
	}
	function al(){
		if( window.top == window.self ) window.location.reload();
		else window.parent.frames[2].location.reload();
	}
}else{
	// 浏览器不支持HTML5
	document.getElementById("preview").innerHTML="浏览器不支持HTML5";
}

</script>
               <form  
              action="" method="post" 
              enctype="multipart/form-data" name="upload" id="upload">
                 <tbody>
                   <tr>
                     <td colspan="2" height="28">&nbsp;&nbsp;&nbsp;&nbsp;
                       <script>
var loadNum=0;
var loadTimes = 3;
checkShowSize = false;
var alertmsg = "";

function showsize()
{
        var maxfilesize = 204800;
        var showimg = new Image();
        showimg.src = document.upload.Upfile.value;
        if(showimg.fileSize>=1) 
	{
		if(showimg.fileSize > maxfilesize)
		{
			//alert(showimg.fileSize + "/" + showimg.width + "/" + loadNum);
			alertmsg = "您选中的图片大于" + maxfilesize+ ",目前字节数=" + showimg.fileSize;
			return false;
		}
		if(showimg.width > 700)
		{
			var ori_w= showimg.width;
			var ori_h = showimg.height;
			showimg.width = 700;
			showimg.height = ori_h * showimg.width / ori_w;
		}
		if(showimg.width < 5 || showimg.height <5)
		{
			showimg.width = showimg.height = 150;
		}
		document.all.view.innerHTML = "<table width=300 border=0 cellpadding=0 cellspacing=0> <tr><td class=a2 height=35><img src=http://images.sohu.com/cs/sms/alumni3/images/album/jdd03.gif width=4 height=8 border=0> 图片预览：</td></tr> <tr> <td> <table border=0 cellpadding=3 cellspacing=0> <tr><td class=bg2><img src=" + showimg.src + " width="+showimg.width+" height="+showimg.height+"></td></tr></table> </td> </tr></table>";
		document.all.view.style.display = "";
		checkShowSize = true;
		return true;
	} else if(loadNum<loadTimes) {
		loadNum ++ ;
		setTimeout('showsize()',500);	
	} else if(loadNum>=loadTimes){
		checkShowSize = false;
		loadNum = 0;
		alertmsg = "图片字节数=0,请换张图片上传";
		return false;
	}
}

function picsubmit() {
	if(!checkShowSize) {
		setTimeout('showsize()',500);
		alert(alertmsg);
		return false;
	}
	document.upload.PICINTRO.value = trim(document.upload.PICINTRO.value);
	if(document.upload.PICINTRO.value.length>30) {
		alert("您的图片介绍超过30字,目前字数="+upload.PICINTRO.value.length);
		return false; 
	}

	filename = document.upload.Upfile.value.toLowerCase();
	filext = filename.substring(filename.length-3,filename.length); 
	if(filext!="jpg" &&  filext!="gif" &&  filext!="png") {
		alert("您上传的图片不是jpg或gif格式");
		return false;
	}
	if(document.upload.share2school.checked) {
		document.upload.STATUS.value = 11;
	}
	else { document.upload.STATUS.value = 1;
	}
	return true;
}
                       </script>
                       <input 
                  class="bg4" type="file" 
                  name="Upfile" />
                       <input type="submit" name="Submit2" value="提交" />
                       <input onmouseover="this.style.backgroundColor='#FFC864'" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; COLOR: #000000; BORDER-BOTTOM: 1px solid; BACKGROUND-COLOR: #f3f3f3" onmouseout="this.style.backgroundColor='#f3f3f3'" type="reset" value=" 重 置 " name="submit22" />
                       <?php echo $Upfile; ?>
                       <input name = "MAX_FILE_SIZE" type = "hidden" id="MAX_FILE_SIZE" value ="1000000" />
                       <input name = "UploadAction" type = "hidden" id="UploadAction" value = "1" /></td>
                   </tr>
                   <tr>
                     <td colspan="2" height="16"><div id="view" style="DISPLAY: none"> </div></td>
                   </tr>
                 </tbody>
               </form>
             </table>
             <p>&nbsp;</p>
             <table width="100%"  border="1" cellspacing="1" cellpadding="1">
               <tr>
                 <td>目前已使用：
                   <?php
$bb = $Filepath;
$cc = dirsize("$bb");
$aa =round($cc/1024/1024*100)/100;
echo $aa.MB."
"."
"; 
?></td>
               </tr>
             </table>
             <p>
               <?php			
				$del=$_GET['del'];
				$oldname=$_POST['oldname'];
				$newname=$_POST['newname'];
				$procesado=$_GET['procesado'];
				  if (!empty($del)) { 
					  $delfile=$Filepath.$del;
					  if(unlink($delfile)){echo "删除 $del 成功";}
					  }
				if (!empty($oldname)) {
					if (rename($Filepath.$oldname,$Filepath.$newname)) echo "成功把 $oldname 改名为 $newname 。"; 
					else echo " $oldname 改名不成功";
				}
				if (!empty($procesado)) {
					 if (strpos($procesado,'PID')>0) {
						if (rename($Filepath.$procesado,$Filepath."done/".$procesado)) echo "处理 $procesado 。"; 
						else echo " $procesado 处理不成功";
					 }else{
						 $procesadoold=str_replace('DONE-','',$procesado);
							if (rename($Filepath.$procesado,$Filepath.$procesadoold)) echo "处理 $procesado 。"; 
						else echo " $procesado 处理不成功";
				 }
				} 
				?>
             </p>
             <table width='100%' border='1' cellpadding='2' cellspacing='0' bordercolor="#999999" bgcolor="#dedede">
               <tr bgcolor="dedede">
   <?php
 
function format_bytes($size) { 
$units = array(' B', ' KB', ' MB', ' GB', ' TB'); 
for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024; 
return round($size, 2).$units[$i]; 
} 
 
?>      <?php 
$dir = $Filepath;
if (is_dir($dir)) {
 if ($dh = opendir($dir)) {
  $i = 0;
  while (($file = readdir($dh)) !== false) {
   if ($file != "." && $file != "..") {
    $files[$i]["name"] = $file;
	$filename=$dir.'/'.$file;
    $files[$i]["size"] = filesize($filename);
    $files[$i]["time"] = date("Y-m-d H:i:s",filemtime($filename));
    $i++;
   }
  }
 }
 closedir($dh);
 foreach($files as $k=>$v){
  $size[$k] = $v['size'];
  $time[$k] = $v['time'];
  $name[$k] = $v['name'];
 }
 array_multisort($time,SORT_DESC,SORT_STRING, $files);//按时间排序
 //array_multisort($name,SORT_DESC,SORT_STRING, $files);//按名字排序
 //array_multisort($size,SORT_DESC,SORT_NUMERIC, $files);//按大小排序
 //print_r($files);
}
?>           <?php
	$arrlength=count($files);
	for($x=0;$x<$arrlength;$x++)  
			{//过滤 . 和 ..
			$entryName=$files[$x]["name"];
				if ($entryName<>"." and $entryName<>".."  and $entryName<>"index.php"  and $entryName<>"admin" ){
				 $n++;
				 ?>
                 <form action='' method='post' name='form1' id="form1">
                   <td width="8%"><img src=" <?php echo "image/".$entryName; ?>" width="80" height="30" alt=""/></td>
                   <td width="50%"><input name='oldname' type='hidden' id='oldname' value='<?php echo $entryName; ?>' />
                     <?php echo $entryName; ?></td>
                     <td width="42%" align="right"   ><?php echo format_bytes($files[$x]["size"]);
?></td>
                  <tr bgcolor="dedede">  <td colspan="3" align="right" ><?php
echo $files[$x]["time"];?> 
                   	 <a href='<?php echo $Filepath.$entryName; ?>' onclick='window.open(this.href,&quot;&quot; ,&quot;toolbar=no,location=no,status=no,scrollbars=1,resizabl=1,menubar=no&quot;); return false'>[ 显 示 ]</a>     <a href='<?php echo "?del=".$entryName; ?>'>[ 删 除 ]</a>  
                     <input name='newname' type='text' id='newname' value='<?php echo $entryName; ?>' size='20' />
                    <input type='submit' name='Submit' value=' 改 名 ' />
                    </td> 
                   </tr>
                 </form>
                 <?php
				  //<img src='../img-shopimg/$entryName ' width='150' height='169'> 显示图片
				 $nn++;
				 }
				 if ($nn==1) {echo  '</tr><tr> ';$nn=0;}
			}
			 
			$num=0;
			?>
               </tr>
             </table></td>
         </tr>
       </tbody>
     </table>
</body>
</html>