简单在线文件系统管理
文件的遍历,我还没写完找时间写
onlineEditor.php文件代码<?php <br />
<br>
//在线文件编辑器<br>
/*-------------------------------------<br>
使用工厂设计模式,MVC实现<br>
*/<br>
<br>
class onlineEditor{<br>
<br>
//设置全局变量路径<br>
public $filePath = null;<br>
//设置过滤信息<br>
private $fileFilter = array(<br>
'onlineEditor.php', <br>
'viewEditor.html',<br>
'index.php',<br>
'.',<br>
'..'<br>
);<br>
<br>
//构造函数必须是私有的在单例设计模式中<br>
function __construct($filePath){<br>
$this->filePath = $filePath;<br>
}<br>
<br>
//当本类销毁的时候进行的操作<br>
function __destruct(){<br>
// echo $this->filePath;<br>
}<br>
<br>
//获取文件的内容<br>
function getContent($filePath){<br>
if (!isset($filePath)) {<br>
<br>
} else{<br>
//获取文件内容<br>
$fileContent = file_get_contents($filePath);<br>
return $fileContent;<br>
}<br>
}<br>
<br>
//放入文件内容<br>
function putContent($filePath,$fileContent){<br>
file_put_contents($filePath, $fileContent);<br>
}<br>
<br>
//判断目录是否存在<br>
private function judgeExist(){<br>
//判断目录是否为空或者没有文件<br>
if(is_dir($this->filePath) && file_exists($this->filePath)){<br>
return true;<br>
} else{<br>
return false;<br>
}<br>
}<br>
<br>
//创建文件<br>
function createFile($filename){<br>
if(!file_exists($filename)){<br>
fopen($filename, "w+");<br>
}<br>
<br>
else{<br>
echo "<a>点此返回</a>";<br>
die("文件已经存在");<br>
}<br>
<br>
}<br>
//删除文件<br>
function delFile($filename){<br>
if(file_exists($filename)){<br>
unlink($filename);<br>
}<br>
}<br>
<br>
//主函数<br>
function main(){<br>
if($this->judgeExist()){<br>
//获取打开文件夹对象<br>
$fileOpen = opendir($this->filePath);<br>
$fileMes = array();<br>
$i = 0;<br>
//遍历文件夹<br>
while ($file = readdir($fileOpen)) {<br>
<br>
//过滤<br>
if(in_array($file, $this->fileFilter)){<br>
continue;<br>
}<br>
<br>
$fileMesPush = array(<br>
'fileCode' => $i,<br>
'fileName' => $file,<br>
'fileType' => fileType($file),<br>
'fileSize' => fileSize($file),<br>
'filemtime' => filemtime($file)<br>
);<br>
<br>
array_push($fileMes, $fileMesPush);<br>
$i++;<br>
}<br>
//关闭文件<br>
<br>
return $fileMes;<br>
fclose($fileOpen);<br>
} else{<br>
die("不存在此文件夹");<br>
}<br>
}<br>
<br>
}<br>
<br>
?>
index.php<?php <br />
<br>
<br>
$dirPath = "./"; //设置操作目录 可改成自选操作目录<br>
$action = null;<br>
<br>
//引入文件<br>
require "./onlineEditor.php";<br>
<br>
//获得onlineEditor对象<br>
$onlineEditor = new onlineEditor($dirPath);<br>
$fileMes = $onlineEditor->main();<br>
<br>
//处理文件路径<br>
function subFilePath($dirPath,$filename){<br>
// echo $dirPath . $filename;<br>
return $dirPath . $filename;<br>
}<br>
<br>
//初始化<br>
if(array_key_exists('action', $_GET)){<br>
switch ($_GET['action']) {<br>
case 'updata':<br>
$action = 'updata';<br>
break;<br>
case 'del':<br>
$onlineEditor->delFile(subFilePath($dirPath,$_GET['filename']));<br>
$action = 'del';<br>
echo subFilePath($dirPath,$_GET['filename']);<br>
echo "<script>location.href = 'index.php';</script>";<br>
break;<br>
}<br>
} else{<br>
$action = null;<br>
}<br>
<br>
if(array_key_exists('action', $_POST)){<br>
switch ($_POST['action']) {<br>
case 'create':<br>
$onlineEditor->createFile(subFilePath($dirPath,$_POST['filename']));<br>
echo "<script>location.href = 'index.php';</script>";<br>
break;<br>
}<br>
}<br>
<br>
//获取文件内容<br>
if(array_key_exists('filename', $_GET) && $_GET['action'] == 'updata'){<br>
$root = subFilePath($dirPath,$_GET['filename']);<br>
$fileContent = $onlineEditor -> getContent($root);<br>
} else<br>
$fileContent = "坚持就是胜利";<br>
<br>
if (array_key_exists('filecontent', $_POST)) {<br>
// var_dump($_POST);<br>
$onlineEditor->putContent(subFilePath($dirPath,$_POST['filename']),$_POST['filecontent']);<br>
echo "<script>location.href = 'index.php';</script>";<br>
} <br>
<br>
<br>
//引入界面<br>
require "./viewEditor.html";<br>
<br>
// print_r($fileMes);<br>
<br>
<br>
<br>
?>
viewEditor.php<br>
<br>
<meta> <br>
<title>在线文件编辑器</title>
<br>
<style><br />
*{margin: 0;padding: 0;}<br />
table{text-align: center;}<br />
.fileMes{width: 800px;height: auto;margin: 0 auto;background: #abcdef;}<br />
.fileMes table tr{height: 30px;}<br />
.fileMes table tr td{border: 1px #fff solid;padding: 10px;}<br />
.updata{width: 800px;height:auto;margin: 0 auto;background: #fff;}<br />
.updata textarea{width: 100%;height: 300px;text-align: left;}<br />
.btn{width:100px;height: 30px; }<br />
.createFile{width:500px;height:auto;margin: 0 auto;margin-bottom:20px;margin-left:400px; }<br />
</style>
<br>
<script><br />
function backIndex(){<br />
location.href = 'index.php';<br />
}<br />
function clearTxt(){<br />
document.getElementById('txt');<br />
txt.innerHTML = "";<br />
}<br />
</script><br>
<br>
<br>
<br>
<br>
<div>
<br>
<br><br><br>
<h2 id="文件在线管理">文件在线管理</h2>
<br>
<br><br><br>
<hr>
<br>
<br><br><br>
<?php <br />
if($action == 'updata'){<br>
?><br>
<div>
<br>
<form>
<br>
<textarea><?php echo $fileContent; ?></textarea><br>
<input>" name="filename" /><br>
<input><br>
<input><br>
<a><input></a><br>
</form>
<br>
</div>
<br>
<br><br><br>
<?php <br />
}<br>
?><br>
<!--创建文件--><br>
<div>
<br>
<form>
<br>
<input><br>
<input><br>
<input><br>
</form>
<br>
</div>
<br>
<div>
<br>
<table>
<br>
<tr>
<br>
<th>序号</th>
<th>文件名</th>
<th>文件类型</th>
<th>文件大小</th>
<th>创建日期</th>
<th>其他操作</th>
<br>
</tr>
<br>
<?php <br />
foreach ($fileMes as $v){ <br>
?><br>
<tr>
<br>
<td><?php echo $v['fileCode'];?></td>
<br>
<td><?php echo $v['fileName'];?></td>
<br>
<td><?php echo $v['fileType'];?></td>
<br>
<td><?php echo $v['fileSize'];?></td>
<br>
<td><?php echo date("Y-m-d",$v['filemtime']);?></td>
<br>
<td><a> >修改</a></td>
<br>
<td><a> >删除</a></td>
<br>
</tr>
<br>
<?php <br />
}<br>
?><br>
</table>
<br>
</div>
<br>
</div>
<br>
<br>
<br>
内容杂,详情请下载代码。
简单的文件在线管理.zip
( 4.36 KB 下载:144 次 )
AD:真正免费,域名+虚机+企业邮箱=0元

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기
