网站在线文件管理
简单在线文件系统管理
文件的遍历,我还没写完找时间写
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元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Learn about Python programming with introductory code examples Python is an easy-to-learn, yet powerful programming language. For beginners, it is very important to understand the introductory code examples of Python programming. This article will provide you with some concrete code examples to help you get started quickly. Print HelloWorldprint("HelloWorld") This is the simplest code example in Python. The print() function is used to output the specified content

PHP variables store values during program runtime and are crucial for building dynamic and interactive WEB applications. This article takes an in-depth look at PHP variables and shows them in action with 10 real-life examples. 1. Store user input $username=$_POST["username"];$passWord=$_POST["password"]; This example extracts the username and password from the form submission and stores them in variables for further processing. 2. Set the configuration value $database_host="localhost";$database_username="username";$database_pa

"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a

Title: From Beginner to Mastery: Code Implementation of Commonly Used Data Structures in Go Language Data structures play a vital role in programming and are the basis of programming. In the Go language, there are many commonly used data structures, and mastering the implementation of these data structures is crucial to becoming a good programmer. This article will introduce the commonly used data structures in the Go language and give corresponding code examples to help readers from getting started to becoming proficient in these data structures. 1. Array Array is a basic data structure, a group of the same type

The simplest code example of Java bubble sort Bubble sort is a common sorting algorithm. Its basic idea is to gradually adjust the sequence to be sorted into an ordered sequence through the comparison and exchange of adjacent elements. Here is a simple Java code example that demonstrates how to implement bubble sort: publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

Huawei Cloud Edge Computing Interconnection Guide: Java Code Samples to Quickly Implement Interfaces With the rapid development of IoT technology and the rise of edge computing, more and more enterprises are beginning to pay attention to the application of edge computing. Huawei Cloud provides edge computing services, providing enterprises with highly reliable computing resources and a convenient development environment, making edge computing applications easier to implement. This article will introduce how to quickly implement the Huawei Cloud edge computing interface through Java code. First, we need to prepare the development environment. Make sure you have the Java Development Kit installed (

Java Selection Sorting Method Code Writing Guide and Examples Selection sorting is a simple and intuitive sorting algorithm. The idea is to select the smallest (or largest) element from the unsorted elements each time and exchange it until all elements are sorted. This article will provide a code writing guide for selection sorting, and attach specific Java sample code. Algorithm Principle The basic principle of selection sort is to divide the array to be sorted into two parts, sorted and unsorted. Each time, the smallest (or largest) element is selected from the unsorted part and placed at the end of the sorted part. Repeat the above

How to use PHP to write the inventory management function code in the inventory management system. Inventory management is an indispensable part of many enterprises. For companies with multiple warehouses, the inventory management function is particularly important. By properly managing and tracking inventory, companies can allocate inventory between different warehouses, optimize operating costs, and improve collaboration efficiency. This article will introduce how to use PHP to write code for inventory warehouse management functions, and provide you with relevant code examples. 1. Establish the database before starting to write the code for the inventory warehouse management function.
