<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<html xmlns= "http://www.111cn.net/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta http-equiv= "Cache-control" content= "No-cache, must-revalidate" >
<title>ajax+php Tutorial File Management system </title>
<style type= "Text/css Tutorial" >
@charset "Utf-8";
/* CSS Document * *
<!--
Body {
padding-right:0px;
padding-left:0px;
padding-bottom:0px;
margin:0px Auto;
Color: #777;
line-height:18px;
padding-top:0px;
Font-family:tahoma, ARIAL, Helvetica, Sans-serif;
Background-color: #fff
}
*+html Body {
padding-right:0px;
padding-left:0px;
padding-bottom:0px;
margin:0px Auto;
Color: #777;
line-height:18px;
padding-top:0px;
font-family: "Microsoft Ya Hei", Ahoma, Arial, Helvetica, Sans-serif;
Background-color: #fff
}
A
Text-decoration:none
}
Input {
padding-right:0px; padding-left:0px; padding-bottom:0px; margin:0px; padding-top:0px
}
. Main {
Background-color: #bfe6bc;
margin:100px Auto;
width:800px;
height:180px;
border:8px #399c26 Solid;
}
. header {
Text-align:center;
margin:10px Auto;
width:100%;
Display:block
}
. header H1 {
font-size:20px;
Color: #399c26
}
. Header P {
padding:0px;
margin-top:-10px;
}
. Header P span{
font-size:12px;
Color: #fff
}
. button_list {
margin:10px Auto;
width:382px;
height:110px;
Display:block
}
. button {
width:100px;
border:8px #399c26 Solid;
height:20px;
line-height:20px;
font-size:14px;
Float:left;
Text-align:center;
margin-left:10px;
margin-bottom:10px;
Background-color: #399c26
}
. Button a{
Color: #fff;
Font-weight:bold
}
. footer {
Text-align:center;
font-size:12px;
Display:block;
margin:10px Auto;
}
. black_overlay{
Display:none;
Position:absolute;
top:0%;
left:0%;
width:100%;
height:100%;
Background-color:black;
z-index:1001;
-moz-opacity:0.8;
opacity:.80;
Filter:alpha (opacity=80);
}
. file_list {
Display:none;
Position:absolute;
top:25%;
left:25%;
width:50%;
height:50%;
padding:16px;
border:8px solid #399c26;
Background-color:white;
z-index:1002;
Overflow:auto;
Background-color: #bfe6bc;
}
. file_list_t {
margin:0 Auto;
Display:inline;
}
. file_list_t Li {
font-size:14px;
List-style-type:none;
padding:0px;
Background-color: #bfe6bc;
border-bottom:1px #ccc Solid;
}
*+html. file_list_t Li {
font-size:14px;
Background:url (images/list_ico_1.gif) #fff no-repeat 7px 50%;
List-style-type:none;
text-indent:5px;
padding:0px;
Background-color: #bfe6bc;
border-bottom:1px #ccc Solid;
}
*+html. file_list_t Li Span {
Float:right;
Font-weight:bold;
margin-top:-20px;
}
. file_list_t Li Span {
Float:right;
Font-weight:bold;
margin-top:0px;
}
. file_list_t Li A{
Color: #399c26;
}
. file_list_close {
Display:none;
Position:absolute;
top:22%;
left:75%;
width:30px;
height:16px;
border:1px solid #399c26;
z-index:1002;
Background-color: #399c26;
Color: #fff;
line-height:16px;
Text-align:center
}
. File_list_close a{
Color: #fff;
}
* File_content_input_form * *
. file_content_input_form{
margin:0 Auto;
width:450px;
padding:14px;
}
* Input_box * *
#input_box {
}
#input_box H1 {
font-size:14px;
Font-weight:bold;
margin-bottom:8px;
}
#input_box p{
font-size:11px;
Color: #399c26;
margin-bottom:20px;
Border-bottom:solid 1px #b7ddf2;
padding-bottom:10px;
}
#input_box label{
Display:block;
Font-weight:bold;
Text-align:right;
width:140px;
Float:left;
}
#input_box. small{
Color: #399c26;
Display:block;
font-size:11px;
Font-weight:normal;
Text-align:right;
width:140px;
}
#input_box input{
Float:left;
font-size:12px;
PADDING:4PX 2px;
Border:solid 1px #399c26;
width:200px;
margin:2px 0 20px 10px;
}
#input_box textarea{
Float:left;
font-size:12px;
PADDING:4PX 2px;
Border:solid 1px #399c26;
width:200px;
height:150px;
margin:2px 0 20px 10px;
}
#input_box button{
Clear:both;
margin-left:150px;
width:125px;
height:31px;
Background: #399c26;
Text-align:center;
line-height:31px;
Color: #ffffff;
font-size:11px;
Font-weight:bold;
}
-->
</style>
<script type= "text/web Effects" src= "ajax. Web Effects" ></script>
<body>
<div class= "Main" >
<div class= "Header" >
<h1> Welcome to use anfms</h1>
<p><span>v0.1.0 alpha</span></p>
</div>
<div class= "Button_list" >
<div class= "button" ><a href= Web page special effects: void (0); "onclick=" javascript:file_list ('/');d Ocument.getelementbyid (' File_list '). style.display= ' block ';d the Ocument.getelementbyid (' File_list_close '). style.display= ' block '; document.getElementById (' fade '). style.display= ' block ' > file list </a></div>
<div class= "button" ><a href= "javascript:void (0);" onclick= "javascript:file_list ('/'); document.getElementById (' File_make '). style.display= ' block ';d ocument.getelementbyid (' File_list_close '). style.display= ' block ';d ocument.getelementbyid (' fade '). style.display= ' blocks ' > create file </a></div>
<div class= "button" ><a href= "javascript:void (0);" onclick= "document.getElementById (' File_content_input ') . style.display= ' block ';d ocument.getelementbyid (' File_list_close '). style.display= ' block '; document.getElementById (' fade '). style.display= ' block ' > Write content </a></div>
<div class= "button" ><a href= "javascript:void (0);" onclick= "document.getElementById (' file_get_content '). style.display= ' block ';d ocument.getelementbyid (' File_list_close '). style.display= ' Block ';d Ocument.getelementbyid (' fade '). style.display= ' block ' > read content </a></div>
</div>
<div class= "Footer" >
<p>
&copy;2009-2010 uniter.com.cn powered by Uniter team<br/>
Supported by ie7+ Firefox opera
</p>
</div>
<div class= "File_list_close" id= "File_list_close" >
<a href= "javascript:void (0);" onclick= "document.getElementById (' file_list '). style.display= ' None '; document.getElementById (' File_content_input '). style.display= ' None ';d ocument.getelementbyid (' file_get_content ') . style.display= ' None ';d ocument.getelementbyid (' File_list_close '). style.display= ' None ';d Ocument.getelementbyid ( ' fade '). style.display= ' None '; Location.reload () ">x</a>
</div>
<div class= "file_list" id= "File_list" ></div>
<div class= "file_list" id= "File_content_input" >
<div id= "Input_box" class= "File_content_input_form" >
<form id= "form" name= "form" method= "POST" action= "" >
<label> file name
<span class= "Small" > For example:abc.txt</span>
</label>
<input type= "text" name= "Input_name" id= "Input_name"/>
<label> Content Value
<span class= "Small" > Add File Content </span>
</label>
<textarea name= "input_content" id= "Input_content" ></textarea>
<button type= "button" onclick= "Javascript:file_content_input (' input_name= ' +document.getelementbyid Name '). value+ ' &input_content= ' +document.getelementbyid (' input_content '). Value); " > OK </button>
<div class= "Spacer" ></div>
</form>
</div>
</div>
<div class= "file_list" id= "File_get_content" >
<div id= "Input_box" class= "File_content_input_form" >
<form id= "Get_form" name= "Get_form" method= "POST" action= "" >
<label> file name
<span class= "Small" > For example:abc.txt</span>
</label>
<input type= "text" name= "Input_name" id= "Input_name"/>
<button type= "button" onclick= "javascript:file_get_content (' input_name= ' +document.get_form.input_name.value);" > OK </button>
<div class= "Spacer" ></div>
</form>
</div>
</div>
<div class= "file_list" id= "File_make" >
<div id= "Input_box" class= "File_content_input_form" >
<form id= "Make_form" name= "Make_form" method= "POST" action= "" >
<label> folders
<span class= "Small" > For example:abc</span>
</label>
<input type= "text" name= "Input_name" id= "Input_name"/>
<button type= "button" onclick= "Javascript:file_make (' input_name= ' +document.make_form.input_name.value);" > OK </button>
<div class= "Spacer" ></div>
</form>
</div>
</div>
<div id= "Fade" class= "Black_overlay" ></div>
</div>
</body>
</html>
Ajax-Web Effects
<script>
JavaScript document
function Do_ajax () {
}
function Ajax_get_data (ID) {
}
function File_list (path) {
var xhr;
if (window.xmlhttprequest) {
XHR = new XMLHttpRequest ();
}else if (window.activexobject) {
XHR = new ActiveXObject ("Msxml2.xmlhttp");
}else {
throw new error ("Ajax is isn't supported by this www.111cn.net browser");
}
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {
if (xhr.status >= && xhr.status < 300) {
document.getElementById (' File_list '). innerHTML = Xhr.responsetext;
}
}
}
Xhr.open (' Get ', ' anfms.php?action=filelist&path= ' +path);
Xhr.setrequestheader ("If-modified-since", "0");
Xhr.send ();
}
function File_content_input (data) {
var data;
var xhr;
if (window.xmlhttprequest) {
XHR = new XMLHttpRequest ();
}else if (window.activexobject) {
XHR = new ActiveXObject ("Msxml2.xmlhttp");
}else {
throw new error ("Ajax is isn't supported by this browser");
}
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {
if (xhr.status >= && xhr.status < 300) {
document.getElementById (' File_content_input '). innerHTML = Xhr.responsetext;
}
}
}
Xhr.open (' Get ', ' anfms.php?action=inputcontent& ' +data);
Xhr.setrequestheader ("If-modified-since", "0");
Xhr.send ();
}
function File_get_content (data) {
var data;
var xhr;
if (window.xmlhttprequest) {
XHR = new XMLHttpRequest ();
}else if (window.activexobject) {
XHR = new ActiveXObject ("Msxml2.xmlhttp");
}else {
throw new error ("Ajax is isn't supported by this browser");
}
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {
if (xhr.status >= && xhr.status < 300) {
document.getElementById (' file_get_content '). innerHTML = Xhr.responsetext;
}
}
}
Xhr.open (' Get ', ' anfms.php?action=getcontent& ' +data);
Xhr.setrequestheader ("If-modified-since", "0");
Xhr.send ();
}
function File_make (file) {
var file;
var xhr;
if (window.xmlhttprequest) {
XHR = new XMLHttpRequest ();
}else if (window.activexobject) {
XHR = new ActiveXObject ("Msxml2.xmlhttp");
}else {
throw new error ("Ajax is isn't supported by this browser");
}
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {
if (xhr.status >= && xhr.status < 300) {
document.getElementById (' File_make '). innerHTML = Xhr.responsetext;
}
}
}
Xhr.open (' Get ', ' anfms.php?action=filemake& ' +file);
Xhr.setrequestheader ("If-modified-since", "0");
Xhr.send ();
}
function File_delete (file) {
var file;
var xhr;
if (window.xmlhttprequest) {
XHR = new XMLHttpRequest ();
}else if (window.activexobject) {
XHR = new ActiveXObject ("Msxml2.xmlhttp");
}else {
throw new error ("Ajax is isn't supported by this browser");
}
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {
if (xhr.status >= && xhr.status < 300) {
document.getElementById (' File_list '). innerHTML = Xhr.responsetext;
}
}
}
Xhr.open (' Get ', ' anfms.php?action=delete_file&file= ' +file);
Xhr.setrequestheader ("If-modified-since", "0");
Xhr.send ();
}
function Dir_delete (file) {
var file;
var xhr;
if (window.xmlhttprequest) {
XHR = new XMLHttpRequest ();
}else if (window.activexobject) {
XHR = new ActiveXObject ("Msxml2.xmlhttp");
}else {
throw new error ("Ajax is isn't supported by this browser");
}
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {
if (xhr.status >= && xhr.status < 300) {
document.getElementById (' File_list '). innerHTML = Xhr.responsetext;
}
}
}
Xhr.open (' Get ', ' anfms.php?action=delete_dir&file= ' +file);
Xhr.setrequestheader ("If-modified-since", "0");
Xhr.send ();
}
</script>
anfms.php
<?php
/**
* All needs file e 111cn.net Manage system
* This is a test code
* Return data to Ajax
* by Aiens
* 2010-01-13 19:20
*/
Header ("content-type:text/html; Charset=utf-8 ");
$document _root = $_server[' Document_root '];
if ($_get[' action '] = = ' FileList ') {//return file list
Echo ' <div class= ' file_list_t ' > ';
$checkpath = Str_replace ($document _root, ', $_get[' path '));
if ($checkpath!= '/.. /') {
$checkpath = Str_replace ('.. /', ', $checkpath);
$path 1 = $document _root.str_replace ($document _root, ', $_get[' path '));
$dir = Opendir ($path 1);
while ($file = Readdir ($dir)) {
if (!) ( $file = = '.. ') {
if ($file = = '. ') {
$path = $path 1. /';
$file = ' return ';
if ($checkpath!= '/') {
Echo ' <li><a href= ' javascript:void (0); "onclick=" Javascript:file_list (". $path."); > '. $file. ' </a></li> ';
}
}else{
$path = $path 1. $file. ' /';
$path = Iconv (' gb2312 ', ' utf-8 ', $path);
if (Is_dir ($path 1 $file)) {
Echo ' <li><a href= ' javascript:void (0); "onclick=" Javascript:file_list (". $path."); > '. $file. ' </a><span><a href= "javascript:void (0);" onclick= "Javascript:if (Confirm (' Confirm deletion ')) Dir_delete ('. $ Path. '); > Delete </a></span></li> ';
}else{
$file = Iconv (' gb2312 ', ' utf-8 ', $file);
$filesize = FileSize ($path 1 $file)/1000;
Echo ' <li> ' $file. '-('. $filesize. ' kb) <span><a href= "javascript:void (0);" onclick= "Javascript:if ( Confirm (' Confirm deletion? ')) File_delete ("$path 1. $file."); > Delete </a></span></li> ';
}
}
}
}
Closedir ($dir);
}
Echo ' </div> ';
}else if ($_get[' action '] = = ' Inputcontent ') {//input data to file
$name = $_get[' input_name '];
$content = $_get[' input_content '];
$data = Date (' y-m-d h:i:s ');
$fp = @fopen (dirname (__file__). /'. $name, ' ab ');
$data = "Data:". $data. " T content: ". $content." n ";
$FW = @fwrite ($fp, $data, strlen ($data));
@fclose ($FP);
if ($FW) {
Echo ' successfully written ';
}else{
Echo ' Write Failed ';
}
}else if ($_get[' action '] = = ' getcontent ') {//get data to file
$name = $_get[' input_name '];
$fp = @fopen (dirname (__file__). /'. $name, ' RB ');
if (! $fp) {
Echo ' www.111cn.net system directory does not exist this file, cannot read ';
Exit
}
while (!feof ($fp)) {
$content = fgets ($FP);
echo $content. ' <br/> ';
}
}else if ($_get[' action '] = = ' Filemake ') {//make dir
$name = $_get[' input_name '];
function MakeDir ($path) {
if (!file_exists ($path)) {
MakeDir (DirName ($path));
return mkdir ($path, 0777);
}
}
if (MakeDir ($name)) {
Echo ' successfully created ';
}else{
Echo ' Create failed ';
}
}else if ($_get[' action '] = = ' Delete_file ') {//delete file
$file = $_get[' file '];
Unlink ($file);
Echo ' successfully deleted ';
}else if ($_get[' action '] = = ' Delete_dir ') {//delete dir
$dir = $_get[' file '];
function Delete_dir ($dir) {
if (! Is_dir ($dir)) {
return false;
}
$handle = @opendir ($dir);
while (($file = @readdir ($handle))!== false) {
if ($file!= '. ' && $file!= ' ... ') {
$dir = $dir. '/' . $file;
Is_dir ($dir)? Delete_dir ($dir): @unlink ($dir);
}
}
Closedir ($handle);
return rmdir ($dir);
}
if (Delete_dir ($dir)) {
Echo ' successfully deleted ';
}else{
Echo ' delete failed ';
}
}
?>