亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

使用前后端分離的web在線管理器。全程使用ajax的請(qǐng)求

Original 2019-03-01 20:22:39 347
abstract:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>簡(jiǎn)易版的web管理器</title> <link href="//netdna.bootstrapcdn.com/font-aw

chakan.png


copy.png


createFile.pngunload.png

unload.png

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>簡(jiǎn)易版的web管理器</title>
		<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
		<style>
			body , ul , li{margin:0;padding:0;}
			/* ul  頭部操作 */
			ul {background:#f1f1f1;height:48px;width:1600px;margin:0 auto;border-radius: 8px 8px 0 0;margin-bottom:8px;}
			ul > li{list-style: none;float: left;display: flex;align-items: center;justify-content: center;height:100%;margin:0 12px;cursor: pointer;}
			
			h2{color:#0056B3}
			table{width:1600px;border:none;margin:0 auto;min-width:1400px;text-align: center;border-collapse: collapse;}
			table a img{height:25px;}
			th {background-color:#6da3da;height:40px;font-weight: 500;color:#fff;background-image:linear-gradient(to bottom , #666 , #aaa);}
			th:first-child{border-radius: 8px 0 0 0;}
			th:last-child{border-radius:0 8px  0 0;}
			td {border:1px solid #999;height:30px;}
			tr td:first-child{border-left: none;}
			tr td:last-child{border-right: none;}
			tr:last-child td {border-bottom:none;}
			.fa {cursor: pointer;width:24px;}
			.zo{color:#a06c6c;}
			.red{color:#e11;}
			.blue{color:#B3D0f0;}
			.lv{color:#87bf87;}
			.yl{color:#d8d8b3;}
			/* 隱藏 */
			.hiddBox{display: none;}
			/* 遮影 */
			.shading{width:100vw;height:100vh;background:rgba(0,0,0,.4);position: fixed;z-index: 8;top:0;left:0;display: none;}
			/* 彈窗 */
			.pop{width:600px;background-color:#f9f9f9;z-index: 99;position: fixed;left:calc(50vw - 300px);top:28%;border-radius: 10px;box-shadow:0 0 10px 2px #999;padding:0 20px;padding-bottom:28px;display: none;}
			.pop p {margin:0;}
				/* 關(guān)閉按鈕 */
				.pop i {position: absolute;
    right: 14px;
    top: 2px;}
				/* 標(biāo)題 */
				.pop-title{text-align: center;font-size:22px;margin:12px 0;}
				/* 文件名 */
				.pop-file{color:#e11;font-weight: 600;margin-right:4px;}
				/* 文本域 */
				.pop textarea{
					margin-top:14px;
					width: 100%;
				outline: none;
				resize: none;
    height: 260px;
    font-size: 14px;
    font-family: 楷體 , 宋體;
    border-radius: 8px;}
				/* 按鈕 */
				.pop-btn{
					margin: 10px auto;
    border: 1px solid #999;
    color: #fff;
    background: #87bf87;
    outline: none;
    display: flex;
    height: 40px;
    padding: 0 20px;
    font-size: 14px;
    border-radius: 8px;
    margin-bottom: 0;
    cursor: pointer;
				}
				/*輸入框*/
			.pop input{
				margin-top: 20px;
				border-radius: 5px;
				outline: none;
				border: 1px solid #999;
				height: 30px;
				width: 100%;
				margin-bottom: 10px;
			}
			/* 上傳文件 */
			.pop-file{
				height:23px!important;
				background-color:#fff!important;;
			}
			
			/*彈窗提示消息*/
			.pop-msg{
				position: absolute;
				bottom:10%;left:10%;
				color: #3c763d;
				background-color: #dff0d8;
				border-color: #d6e9c6;
				border-radius:8px;
				padding:10px 20px;
				text-align: center;
				display: block;
				opacity: 0;
				z-index: 999;
				transition: all 1.2s;
			}
			.pop-msgR{
				left:70%;
				opacity: 1;
			}

			/*提示消息*/
			.title{
				position: fixed;top:50%;left:50%;
				color: #3c763d;
				background-color: #dff0d8;
				border-color: #d6e9c6;
				border-radius: 8px;
				padding:10px 20px;
				text-align: center;
				display: none;
				transform: translate(-50%,-50%);
				z-index: 999;
			}
		</style>
	</head>
	<body>
<!-- 表格 -->
<h2 style="text-align: center;margin:15px 0;">在線WEB文件管理器</h2>
<ul class="ul">
	<li data-act="main" title="主目錄" ><i  class="fa fa-home fa-3x"></i>&nbsp;&nbsp;&nbsp;</li>
	<li data-act="createFile" title="新建文件" ><i  class="fa fa-file fa-2x"></i></li>
	<li data-act="createDir" title="新建目錄" ><i  class="fa fa-file-o fa-2x"></i></li>
	<li data-act="unload" title="上傳文件" ><i  class="fa fa-upload fa-2x"></i></li>
	<li data-act="back" title="上一目錄" ><i  class="fa fa-arrow-left fa-2x"></i></li>
</ul>
<table border="0" cellspacing="0" cellpadding="0" >
	<thead>
		<tr>
			<th>編號(hào)</th>
			<th>名稱</th>
			<th>類型</th>
			<th>大小</th>
			<th>可讀</th>
			<th>可寫</th>
			<th>可執(zhí)行</th>
			<th>創(chuàng)建時(shí)間</th>
			<th>修改時(shí)間</th>
			<th>訪問時(shí)間</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>1</td>
			<td>新建文本</td>
			<td>文件</td>
			<td>1.1kb</td>
			<td>可</td>
			<td>可</td>
			<td>不可</td>
			<td>2019-09-11</td>
			<td>2019-05-11</td>
			<td>2019-09-11</td>
			<td><a href="#" ><img class="small" src="images/show.png" alt="" title="查看"></a>
            <a href="#" ><img class="small" src="images/edit.png" alt="" title="修改"></a>
            <a href="#" ><img class="small" src="images/rename.png" alt="" title="重命名"></a>
            <a href="#" ><img class="small" src="images/copy.png" alt="" title="復(fù)制"></a>
            <a href="#" ><img class="small" src="images/cut.png" alt="" title="剪切"></a>
            <a href="#" ><img class="small" src="images/download.png" alt="" title="下載"></a>
            <a href="#" ><img class="small" src="images/delete.png" alt="" title="刪除"></a>
        </td>
		</tr>
	</tbody>
</table>
<!-- 遮影 -->
<div class="shading"></div>
	<!-- 彈窗 -->
<div class="pop ">
	<!-- 關(guān)閉按鈕 -->
	<i class="fa fa-window-close fa-2x"></i>
	<!-- 操作名稱 -->
	<h3 class="pop-title">查看</h3>
	<!-- 正在操作的文本 -->
	<p ><span class="pop-file">11.txt</span>的文本內(nèi)容如下:</p>
	<textarea rows="100" cols="8" >
	</textarea>
</div>

<!-- 提示 -->
<div class="title">操作成功!??!</div>
		<script src="./list/jquery.min.js" type="text/javascript"></script>
		<script src="js/main.js" type="text/javascript" charset="utf-8"></script>
	</body>
</html>
$(function(){
	var path = 'file';
	var self = null;
	var newName = null;
	var isMain = true;
	//請(qǐng)求獲取目錄
	ajax('http://www.myphp.com/07/zuoye/get.php',{path:path},renderingTable);
    
	//綁定彈窗中的關(guān)閉按鈕
	$('.pop i').on('click',function(){
		console.log(this);
	});

//綁定頭部的ul
$('ul > li').on('click',function(){
	var cuozuo = $(this).attr('data-act');
	switch(cuozuo){
		case 'main':  //等于主目錄時(shí)
		 path = 'file';
		 if(isMain){return console.log("當(dāng)前在主目錄,的返回");}
		 //請(qǐng)求獲取目錄
		 ajax('http://www.myphp.com/07/zuoye/get.php',{path:path},renderingTable);
		 break;
		case 'createFile': 
		  //渲染彈窗
		  popContent('',cuozuo);
		 break;
		case 'createDir':
		  //渲染彈窗
		  popContent('',cuozuo);
		  break;
		case 'unload':
		  //渲染彈窗
		  popContent('',cuozuo);
		  break;
	}
});



/**
 * 渲染彈窗
 * @parma url 該文件
 * @parma act 操作
 * @parma text 文本
 */
function popContent(url,act,text){
	var str = ``;
	switch(act){
		case 'show':  //查看文件
			str += `
			  <i class="fa fa-window-close fa-2x"></i>
			  <h3 class="pop-title">查看</h3>
			  <p><span class="pop-file">${url}</span>的文本內(nèi)容如下:</p>
			  <textarea class="pop-srk" rows="100" cols="8" disabled>	
				  ${text}
			  </textarea>
			`;
			break;
		case 'xgQr':  //修改
			str += `
			  <i class="fa fa-window-close fa-2x"></i>
			  <h3 class="pop-title">修改</h3>
			  <p><span class="pop-file">${url}</span>的文本內(nèi)容如下,請(qǐng)輸入內(nèi)容并按下確定按鈕:</p>
			  <textarea class="pop-srk" rows="100" cols="8">	
				  ${text}
			  </textarea>
			  <button class="pop-btn" data-act=${act} data-url=${url}  >確認(rèn)修改</button>
			`;
			break;
		case 'renameQr': //重命名
			str += `
			<i class="fa fa-window-close fa-2x"></i>
			  <h3 class="pop-title">重命名</h3>
			  <p><span class="pop-file">${url}</span>的重命名,請(qǐng)輸入新的名字并按下確定按鈕:</p>
			  <input class="pop-srk" type="text" value="" />
			  <div class="pop-msg"></div>
			  <button class="pop-btn" data-act=${act} data-url=${url}  >確認(rèn)修改</button>
			`;
			break;
		case 'copy': //復(fù)制
			str += `
			<i class="fa fa-window-close fa-2x"></i>
			  <h3 class="pop-title">復(fù)制</h3>
			  <p><span class="pop-file">${url}</span>的復(fù)制,請(qǐng)輸入路勁即可:</p>
			  <input class="pop-srk" type="text" value="" />
			  <div class="pop-msg"></div>
			  <button class="pop-btn" data-act=${act} data-url=${url}  >確認(rèn)復(fù)制</button>
			`;
			break;
		case 'cut': //剪切
			str += `
			<i class="fa fa-window-close fa-2x"></i>
			  <h3 class="pop-title">剪切</h3>
			  <p><span class="pop-file">${url}</span>的剪切,請(qǐng)輸入路勁即可:</p>
			  <input class="pop-srk" type="text" value="" />
			  <div class="pop-msg"></div>
			  <button class="pop-btn" data-act=${act} data-url=${url}  >確認(rèn)剪切</button>
			`;	
			break;
		case 'createFile':  //創(chuàng)建文件
		    str += `
		      <i class="fa fa-window-close fa-2x"></i>
		      <h3 class="pop-title">創(chuàng)建文件</h3>
		      <p>請(qǐng)輸入你要?jiǎng)?chuàng)建的文件名:</p>
		      <input class="pop-srk" type="text" value="" />
		      <div class="pop-msg"></div>
		      <button class="pop-btn" data-act=${act} data-url=${url}  >確認(rèn)創(chuàng)建</button>
		    `;	
			break;
		case 'createDir': //創(chuàng)建文件夾
		    str += `
		      <i class="fa fa-window-close fa-2x"></i>
		      <h3 class="pop-title">創(chuàng)建文件夾</h3>
		      <p>請(qǐng)輸入你要?jiǎng)?chuàng)建的文件夾名:</p>
		      <input class="pop-srk" type="text" value="" />
		      <div class="pop-msg"></div>
		      <button class="pop-btn" data-act=${act} data-url=${url}  >確認(rèn)創(chuàng)建</button>
		    `;
		    break;
		case 'unload'://上傳文件	
		  str += `
		    <i class="fa fa-window-close fa-2x"></i>
		    <h3 class="pop-title">上傳文件</h3>
		    <p>請(qǐng)選擇你要上傳的文件</p>
		    <input  class="pop-file pop-srk" id="file" type="file" name="file" value="" />
		    <div class="pop-msg"></div>
		    <button class="pop-btn" data-act=${act} data-url=${url}  >確認(rèn)上傳</button>
		  `;
		  break;
	}
	//設(shè)置jq
	$('.pop').html(str);
	closePop(true);
	//綁定關(guān)閉按鈕
	$('.pop i').on('click',function(){
		closePop(false);
	});

	//綁定按鈕
	$('.pop-btn').on('click',function(){
		newName =  $('.pop .pop-srk')[0] > 1 ? $('.pop .pop-srk').val().trim() : '22222';
		var act = $(this).attr('data-act');
		if($('.pop .pop-srk').val().trim() == 0){
			/*
			//用時(shí)間戳當(dāng)判斷
			window.time = window.time ? window.time : 0;
			var nowTime = new Date().getTime();
			if(nowTime - window.time <= 2000){
				console.log('動(dòng)畫執(zhí)行中,返回!!!');
			}
			window.time = nowTime;
			*/

            //阻止用戶連續(xù)點(diǎn)擊,用提示類的屬性來判斷
			if($('.pop-msg').css('opacity') != '0'){
				return console.log("動(dòng)畫執(zhí)行中,111返回?。。?quot;);
			}

            $('.pop-msg').text('名字不能為空!').addClass('pop-msgR');
            setTimeout(function(){
                $('.pop-msg').removeClass('pop-msgR');
			},2000);
			return ;
		}
		
		//如果是復(fù)制
		if(act == 'copy'){
			var nowLujin = newName;
			var list = $('.pop-file').text().trim().split('/');
			newName = list[0].toString() + '/' + newName +'/'+ list[1];
		//如果是剪切	
		}else if(act == 'cut'){
			var nowLujin = newName;
			var list = $('.pop-file').text().trim().split('/');
			newName = list[0].toString() + '/' + newName ;
		//如果是創(chuàng)建文件或創(chuàng)建文件夾
		}else if(act == 'createFile' || act == 'createDir'){ 
			$(this).attr('data-url',path+'/'+$('.pop input').val().trim())
		//上傳文件	
		}else if(act == 'unload'){
			//創(chuàng)建表單
			var formData = new FormData();
			//添加數(shù)據(jù)
            formData.append('file',document.getElementsByName('file')[0].files[0]);
            formData.append('act',act);
			
			//此處是用ajax上傳文件給后臺(tái)
            $.ajax({
	              url: 'http://www.myphp.com/07/zuoye/caozuo.php',	
                  type:'post',
				  data: formData,
				  processData : false , //設(shè)置數(shù)據(jù)不需要進(jìn)行處理  ,  重要
				  contentType : false , //設(shè)置發(fā)送的數(shù)據(jù)不進(jìn)行處理  , 重要  后臺(tái)才能接受到文件和數(shù)據(jù)等。
				  success : function(res){
					  changeData(JSON.parse(res));
				  }
            });
			closePop(false);
			return;
		}
		
		
			
		//請(qǐng)求后臺(tái)數(shù)據(jù)
		ajax('http://www.myphp.com/07/zuoye/caozuo.php',{file:$(this).attr('data-url'),act:act,text:$('.pop textarea').val(),newName:newName,dir:$('.pop input').val()},changeData,'post');
		closePop(false);
	});
}

/**
 * 彈窗動(dòng)畫
 */
function closePop(bool){
	if(bool){
		$(".pop").slideDown(400);
		$(".shading").slideDown(100);
	}else{
		$(".pop").slideUp(350);
		$(".shading").slideUp(200);
	}
}

/**
 * 請(qǐng)求數(shù)據(jù)
 */
function ajax(url,data,fun,method = 'GET'){
	$.ajax({
	      method:method,
	      url:url,
	      data: data,
	     success(res){
			 try{
			 	dataAll = JSON.parse(res);
				fun(dataAll);
			 }catch(e){
				alert("數(shù)據(jù)返回錯(cuò)誤!!!");
			 }
	     },
	     error(e){
			 console.log(e);
			  alert("請(qǐng)求失敗,2秒后刷新頁面?。?!");
			  setTimeout("location.href = location.href",2000);
	     }
	});
}

/**
 * i對(duì)應(yīng)的操作請(qǐng)求成功
 */
function changeData(res){
	console.log(res);
	//判斷是否為提示消息
	if(res.act == 'title'){
		//是否有返回新名字  重名操作
		if(res.cuozuo && res.cuozuo == 'renameQr'){
			$(self).parent().attr('data-url',path+"/"+res.newName).parent().find('td:nth-child(2)').text(res.newName);
		//復(fù)制操作	
		}else if(res.cuozuo && (res.cuozuo == 'copy' || res.cuozuo == 'cut')){
			//請(qǐng)求獲取目錄
			ajax('http://www.myphp.com/07/zuoye/get.php',{path:path},renderingTable);
		//刪除操作	
		}else if(res.cuozuo && res.cuozuo == 'del'){
			//請(qǐng)求獲取目錄
			ajax('http://www.myphp.com/07/zuoye/get.php',{path:path},renderingTable);
		//創(chuàng)建操作	
		}else if(res.cuozuo && (res.cuozuo == 'createFile' || res.cuozuo == 'createDir')){
			//請(qǐng)求獲取目錄
			ajax('http://www.myphp.com/07/zuoye/get.php',{path:path},renderingTable);
		}
		
		
		
        setTimeout(function () {
            $('.title').text(res.msg).slideDown(200).delay(1500).slideUp(200);
        },500);
	}else{
		popContent(res.url,res.act,res.data);
	}
}



/**
 * 渲染數(shù)據(jù)
 */
function renderingTable(res){
	var list = res.data;
	let str;
	for(var i=0;i<list.length;i++){
		str += `
			<tr>
				<td>${(i+1)}</td>
				<td>${list[i].name}</td>
				<td>${list[i].type == 'file' ? '<i class="fa fa-file-text-o fa-lg" title="文件" ></i>' : '<i class="fa fa-file-o fa-lg" title="文件夾"></i>'}</td>
				<td>${list[i].size}</td>
				<td>${list[i].isKd ? '<i class="fa   fa-hand-peace-o fa-lg"></i>' : '<i class="fa  fa-hand-stop-o fa-lg" ></i>'}</td>,
				<td>${list[i].isKx ? '<i class="fa   fa-hand-peace-o fa-lg"></i>' : '<i class="fa  fa-hand-stop-o fa-lg"></i>'}</td>,
				<td>${list[i].isRun ? '<i class="fa   fa-hand-peace-o fa-lg"></i>' : '<i class="fa  fa-hand-stop-o fa-lg"></i>'}</td>,
				<td>${list[i].ctime}</td>
				<td>${list[i].atime}</td>
				<td>${list[i].mtime}</td>
				<td data-url="${list[i].url}">
					<i class="fa  lv fa-shower fa-lg" title="查看" data-act='show'></i>
			`;
		if(list[i].type == 'file'){
			str += `		<i class="fa  zo fa-pencil fa-lg" title="修改" data-act='xg'></i>
					<i class="fa  yl fa-envelope fa-lg" title="重命名" data-act='rename'></i>
					<i class="fa blue  fa-copy fa-lg" title="復(fù)制" data-act='copy'></i>
					<i class="fa  red fa-cut fa-lg" title="剪切" data-act='cut'></i>
					<i class="fa  lv fa-arrow-circle-down fa-lg" title="下載" data-act='dow'></i>
					<i class="fa  red fa-delicious fa-lg" title="刪除" data-act='del'></i>
			`;
		}else{
			str += `		<i class="fa  yl fa-envelope fa-lg" title="重命名" data-act='rename'></i>
					<i class="fa blue  fa-copy fa-lg" title="復(fù)制" data-act='copy'></i>
					<i class="fa  red fa-cut fa-lg" title="剪切" data-act='cut'></i>
					<i class="fa  red fa-delicious fa-lg" title="刪除" data-act='del'></i>
			`;
		}
				str += `	</td>
			</tr>`;
	}
	$('tbody').html(str);
	//數(shù)據(jù)渲染完成
	//根據(jù)每個(gè)操作對(duì)應(yīng)的顯示彈窗
	$('table td:last-child i').on('click',function(){
		var act = $(this).attr('data-act');
		//查看或修改
		if(act == 'show' || act == 'xg'){
			//請(qǐng)求后臺(tái)數(shù)據(jù)
			ajax('http://www.myphp.com/07/zuoye/caozuo.php',{file:$(this).parent().attr('data-url'),act:act},changeData,'post');
		//重命名	
		}else if(  act == 'rename'){
			//顯示彈窗
			popContent($(this).parent().attr('data-url'),"renameQr");
			self = this;
		//復(fù)制	 || 剪切
		}else if(act == 'copy' || act == 'cut'){
			//顯示彈窗
			popContent($(this).parent().attr('data-url'),act);
		}

        //下載
		if(act == 'dow'){
			//訪問下載鏈接
			location.href = location.href+"caozuo.php?act=dow&file="+$(this).parent().attr('data-url');
		}
		
		//刪除
		if(act == 'del'){
			if(window.confirm("您確定要?jiǎng)h除嘛?刪除之后無法恢復(fù)喲!!!")){
			  //location.href = location.href+"caozuo.php?act=del&file="+$(this).parent().attr('data-url')+"&wangzhi="+location.href;
			  //請(qǐng)求后臺(tái)數(shù)據(jù)
			  ajax('http://www.myphp.com/07/zuoye/caozuo.php',{file:$(this).parent().attr('data-url'),act:act},changeData,'post');
			}
		}
		
		//渲染彈窗
		//popContent($(this).parent().attr('data-url'),$(this).attr('data-act'));
	});

}

});
<?php
	include "function.php";

	@$act = $_REQUEST['act'];
	@$fileName = $_REQUEST['file'];
	@$wangzhi = $_REQUEST['wangzhi'];
	$data = [
		'status' => 0,
		'data' => [],
		'act' => $act,
		'url' => $fileName,
		'msg' => '請(qǐng)求成功'
	];

	switch(@$act){
		case 'show': //查看
			//調(diào)用查看函數(shù)
			$data['data'] = read_file($fileName);
			$data['msg'] = '請(qǐng)求文件內(nèi)容成功返回';
			break;
		case 'xg': //修改  ,先返回?cái)?shù)據(jù)給用戶.用戶按下確認(rèn)時(shí)在來處理
			$data['data'] = read_file($fileName);
			$data['act'] = 'xgQr';
			break;
		case 'xgQr': //修改確認(rèn)
			$text = $_POST['text'];
			$mes = write_file($fileName,$text,false);
			$data['msg'] = $mes;
			$data['act'] = 'title'; //提示用戶
			break;
		case 'renameQr': //確認(rèn)修改重命名
		    $data['act'] = 'title';
			$dir = pathinfo($fileName,PATHINFO_DIRNAME);
			@$newName = $_POST['dir'];
			 $mes = rename_file($fileName,$dir.'/'.$newName);
			 $data['msg'] = $mes;
			 $data['cuozuo'] = $act;
			 $data['newName'] = $newName;
		    break;
		case 'copy': //確認(rèn)復(fù)制
		    $data['act'] = 'title';
			@$newName = $_POST['newName'];
			 $mes = copy_file($fileName,$newName);
			 $data['msg'] = $mes;
			 $data['cuozuo'] = $act;
		    break;
		case 'cut': //確認(rèn)復(fù)制
		    $data['act'] = 'title';
			@$newName = $_POST['newName'];
			 $mes = cut_file($fileName,$newName);
			 $data['msg'] = $mes;
			 $data['cuozuo'] = $act;
		    break;	
		case 'dow': //下載
			$data['act'] = 'title';
			$mes = dow_file($fileName);
			$data['msg'] = $fileName;
			break;
		case 'del': //刪除
		  $data['act'] = 'title';
		  $mes = del_file($fileName);
		  $data['msg'] = $mes;
		  $data['cuozuo'] = 'del';
		  break;
		case 'createFile': //創(chuàng)建文件
		  $mes = create_file($fileName);
		  $data['msg'] = $mes;
		  $data['act'] = 'title';
		  $data['cuozuo'] = $act;
		  break;
		case 'createDir': //創(chuàng)建文件夾
		  $mes = createFolder($fileName);
		  $data['msg'] = $mes;
		  $data['act'] = 'title';
		  $data['cuozuo'] = $act;
		  break;  
		case 'unload': //上傳文件
		  $mes  = upload_file($_FILES["file"]);
		  $data['act'] = 'title';
		  $data['msg'] = $mes;
		  break;
	}
	
	echo JSON_encode($data);	
?>
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/19
 * Time: 17:39
 */

/**
 * 創(chuàng)建文件或目錄
 * @param $fileName  需要?jiǎng)?chuàng)建的文件名
 * @return string    提示信息
 */
function create_file($fileName){
    //判斷文件是否存在
    if(file_exists($fileName)){
        return "該文件已存在";
    }

    //判斷目錄是否存在,如果不存在就創(chuàng)建目錄
    if(!file_exists(dirname($fileName))){  // dirname函數(shù) 獲取文件目錄
        mkdir(dirname($fileName),0777,true);
    }

    //touch 用來設(shè)置文件時(shí)間,如果文件不存在則會(huì)創(chuàng)建
    if(touch($fileName)){
        return "文件創(chuàng)建成功";
    }

    return "文件創(chuàng)建失敗";
}

/**
 * 刪除文件的函數(shù)
 * @param $fileName   文件名稱
 * @return string  提示信息
 */
function del_file($fileName){
    //判斷文件是否存在且 判斷該文件是否有權(quán)限進(jìn)行讀寫
    if(!file_exists($fileName) || !is_writable($fileName)){
        return "此文件不可操作";
    }
    //刪除文件
    if(unlink($fileName)){
        return "文件刪除成功";
    }
    return "文件刪除失敗";
}

/**
 * 文件復(fù)制
 * @param $fileName  fileName
 * @param $lujin   Road
 * @return string   prompt Msg
 */
function copy_file($fileName,$lujin){
  if(!file_exists($fileName) || !is_writable($fileName)){
      return "此文件不可操作";
  }

  //檢測(cè)拷貝到的目錄下是否存在有相同的文件
    if(file_exists($lujin)){
        return "該目錄下已存在此文件";
    }

  if(copy($fileName,$lujin)){
      return "OK ! COPY!! ";
  };
  return "Error!!!";
}


/**
 * @param $fileName   文件名
 * @param $newName   需要新的重命名文件
 * @return string  提示的信息
 */
function rename_file($fileName,$newName){
    //判斷參數(shù)是否為正常的文件
    if(!is_file($fileName)){
        return "該類型文件不可重命名!";
    }

    //獲取路勁
    $path = dirname($fileName);
    //拼接路勁
    $destName = $path.DIRECTORY_SEPARATOR.$newName;
    //判斷是否為正常路勁
    if(is_file($destName)){
        return '修改失敗!';
    }
    //進(jìn)行重命名操作并判斷是否成功
    if(rename($fileName,$newName)){
        return "文件重命名成功";
    }
    return "文件重命名失敗";
}

/**
 * 剪切的函數(shù)
 * @param $fileName  剪切的文件
 * @param $newName  需要剪切的路勁
 * @return string  提示信息
 */
function cut_file($fileName,$newName){
    //判斷文件是否存在
    if(!is_file($fileName)){
        return "此文件不可操作!";
    }

    //判斷是否存在該文件夾,不存在則創(chuàng)建
    if(!is_dir($newName)){
        mkdir($newName,0777);
    }


    //拼接路勁
    $destName = $newName.DIRECTORY_SEPARATOR.basename($fileName);

    //判斷是否為正常的文件夾
    if(file_exists($destName)){
        return "該文件夾下已存在此文件!";
    }

    if(rename($fileName,$destName)){
        return "剪貼成功";
    }
     return "剪貼失?。?quot;;
}

/**
 * 文件信息查詢操作
 * @param $fileName   文件名
 * @return array|string 文件信息相關(guān)數(shù)組| false
 */
function get_file_info($fileName){
    //判斷文件是否文真是的文件
    if(!is_file($fileName) && !is_readable($fileName)){
        return "沒有該文件,或此文件不可讀";
    }
   return [
       'type' => filetype($fileName),
       'ctime' => date('Y-m-d H:i:s',filectime($fileName)),
       'mtime' => date('Y-m-d H:i:s',filemtime($fileName)),
       'atime' => date('Y-m-d H:i:s',fileatime($fileName)),
       'size' => trans_byte(filesize($fileName))
       ];
}

/**
 * @param $byte   字節(jié)大小
 * @param int $precision   精確到兩位數(shù)字
 * @return string  文件大小信息
 */
function trans_byte($byte,$precision=2){
    $kb = 1024;
    $mb = 1024*$kb;
    $gb = 1024*$mb;
    $tb = 1024*$gb;

    if($byte < $kb){
        return $byte.'B';
    }elseif($byte < $mb){
        return round($byte/$kb,$precision).'KB';
    }elseif($byte < $gb){
        return round($byte/$mb,$precision).'MB';
    }elseif($byte < $tb){
        return round($byte/$gb,$precision).'GB';
    }else{
        return round($byte/$tb)."TB";
    }
}

/**
 * 讀取文件信息  字符串
 * @param $fileName  文件名
 * @return bool|string  返回的時(shí)字符串|文件不存在
 */
function read_file($fileName){
    if(file_exists($fileName) && is_readable($fileName)){
        return file_get_contents($fileName);
    }
    return "該文件不存在或不可讀?。?quot;;
}

/**
 * 文件讀取方式,返回的數(shù)組
 * @param $fileName
 * @param bool $bool  是否需要跳過空行
 * @return string   array|false
 */
function read_file_array($fileName,$bool = true){
    if(file_exists($fileName) && is_readable($fileName)){
        if($bool){
            //在數(shù)組每個(gè)元素的末尾不要添加換行符,跳過空行
            return file($fileName,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
        }else{
            //不跳過空行
            return file($fileName);
        }
    }
  return false;
}

/**
 * 文件寫入操作
 * @param $fileName  操作的文件名
 * @param $data  需要寫入的數(shù)據(jù)
 * @param bool $clear  是否清空內(nèi)容
 * @return string  提示信息
 */
function write_file($fileName, $data,$clear = true){
    //判斷文件是否存在 且  可讀寫
    if(file_exists($fileName) && is_writable($fileName)){
        //是否保留原來的內(nèi)容
       if($clear){
         $data.= file_get_contents($fileName);
       }
       file_put_contents($fileName,$data);
       return "文件寫入成功";
    }
    return "文件不存在或不可讀取";
}

/**
 * 文件下載
 * @param $fileName  文件名
 * @return string  提示信息
 */
function dow_file($fileName){
    if(file_exists($fileName)){
        //告訴游覽器需要下載的文件大小
        header('Accpet-Length:'.filesize($fileName));
        //告訴游覽器文件作為附件處理 ,告訴游覽器最終下載完的文件名稱
        header('Content-Disposition:attachment;filename='.basename($fileName));
      //  ob_clean(); //清楚(擦除)輸出緩沖區(qū)
        readfile($fileName); //下載文件
        exit;  //結(jié)束  沒有該語句,則會(huì)連源碼也會(huì)作為附件一起下載給用戶
    }
    return "文件不存在";
}

/**
 * @param $fileInfo  文件信息
 * @param string $uploadPath 文件到的目錄
 * @param bool $imageFlag   是否檢查圖片
 * @param array $allowExt  規(guī)定的文件類型
 * @param int $maxSize  最大大小設(shè)置
 */
function upload_file($fileInfo,$uploadPath = './upload',$imageFlag = true , $allowExt = ['jpg', 'png', 'jpeg', 'gif', 'txt','xls'], $maxSize = 2097152){
  //判斷文件是否有錯(cuò)誤,error  等于0  表示沒有錯(cuò)誤
    if($fileInfo['error'] == 0){
      //截取上傳文件的后綴
        $ext = strtolower(pathinfo($fileInfo['name'],PATHINFO_EXTENSION));
        //判斷上傳的文件是否符合類型
        if(!in_array($ext,$allowExt)){
            return "文件類型不符";
        }
        //判斷上傳的大小是否符合
        if($maxSize - $fileInfo['size'] < 0){
            return "文件大小超出";
        }
        //判斷是否有upload目錄
        if(!is_dir($uploadPath)){
            mkdir($uploadPath,0777,true);
        }
       &amp				

Correcting teacher:韋小寶Correction time:2019-03-02 09:06:08
Teacher's summary:寫的非常棒 ! ! 整個(gè)樣式改的很美觀 通過ajax的請(qǐng)求 體驗(yàn)也得到了提升

Release Notes

Popular Entries