ajax+php File Management System

Source: Internet
Author: User
Tags button type php file php tutorial

<!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>

&lt;body&gt;


&lt;div class= "Main" &gt;


&lt;div class= "Header" &gt;


&lt;h1&gt; Welcome to use anfms&lt;/h1&gt;


&lt;p&gt;&lt;span&gt;v0.1.0 alpha&lt;/span&gt;&lt;/p&gt;


&lt;/div&gt;


&lt;div class= "Button_list" &gt;


&lt;div class= "button" &gt;&lt;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 ' &gt; file list &lt;/a&gt;&lt;/div&gt;


&lt;div class= "button" &gt;&lt;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 ' &gt; create file &lt;/a&gt;&lt;/div&gt;


&lt;div class= "button" &gt;&lt;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 ' &gt; Write content &lt;/a&gt;&lt;/div&gt;


&lt;div class= "button" &gt;&lt;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 ' &gt; read content &lt;/a&gt;&lt;/div&gt;


&lt;/div&gt;


&lt;div class= "Footer" &gt;


&lt;p&gt;


&amp;copy;2009-2010 uniter.com.cn powered by Uniter team&lt;br/&gt;


Supported by ie7+ Firefox opera


&lt;/p&gt;


&lt;/div&gt;





&lt;div class= "File_list_close" id= "File_list_close" &gt;


&lt;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 () "&gt;x&lt;/a&gt;


&lt;/div&gt;


&lt;div class= "file_list" id= "File_list" &gt;&lt;/div&gt;


&lt;div class= "file_list" id= "File_content_input" &gt;


&lt;div id= "Input_box" class= "File_content_input_form" &gt;


&lt;form id= "form" name= "form" method= "POST" action= "" &gt;


&lt;label&gt; file name


&lt;span class= "Small" &gt; For example:abc.txt&lt;/span&gt;


&lt;/label&gt;


&lt;input type= "text" name= "Input_name" id= "Input_name"/&gt;


&lt;label&gt; Content Value


&lt;span class= "Small" &gt; Add File Content &lt;/span&gt;


&lt;/label&gt;


&lt;textarea name= "input_content" id= "Input_content" &gt;&lt;/textarea&gt;


&lt;button type= "button" onclick= "Javascript:file_content_input (' input_name= ' +document.getelementbyid Name '). value+ ' &amp;input_content= ' +document.getelementbyid (' input_content '). Value); " &gt; OK &lt;/button&gt;


&lt;div class= "Spacer" &gt;&lt;/div&gt;


&lt;/form&gt;


&lt;/div&gt;


&lt;/div&gt;


&lt;div class= "file_list" id= "File_get_content" &gt;


&lt;div id= "Input_box" class= "File_content_input_form" &gt;


&lt;form id= "Get_form" name= "Get_form" method= "POST" action= "" &gt;


&lt;label&gt; file name


&lt;span class= "Small" &gt; For example:abc.txt&lt;/span&gt;


&lt;/label&gt;


&lt;input type= "text" name= "Input_name" id= "Input_name"/&gt;


&lt;button type= "button" onclick= "javascript:file_get_content (' input_name= ' +document.get_form.input_name.value);" &gt; OK &lt;/button&gt;


&lt;div class= "Spacer" &gt;&lt;/div&gt;


&lt;/form&gt;


&lt;/div&gt;


&lt;/div&gt;


&lt;div class= "file_list" id= "File_make" &gt;


&lt;div id= "Input_box" class= "File_content_input_form" &gt;


&lt;form id= "Make_form" name= "Make_form" method= "POST" action= "" &gt;


&lt;label&gt; folders


&lt;span class= "Small" &gt; For example:abc&lt;/span&gt;


&lt;/label&gt;


&lt;input type= "text" name= "Input_name" id= "Input_name"/&gt;


&lt;button type= "button" onclick= "Javascript:file_make (' input_name= ' +document.make_form.input_name.value);" &gt; OK &lt;/button&gt;


&lt;div class= "Spacer" &gt;&lt;/div&gt;


&lt;/form&gt;


&lt;/div&gt;


&lt;/div&gt;


&lt;div id= "Fade" class= "Black_overlay" &gt;&lt;/div&gt;


&lt;/div&gt;


&lt;/body&gt;


&lt;/html&gt;

Ajax-Web Effects

&lt;script&gt;


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 &gt;= &amp;&amp; xhr.status &lt; 300) {


document.getElementById (' File_list '). innerHTML = Xhr.responsetext;


}


}


}


Xhr.open (' Get ', ' anfms.php?action=filelist&amp;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 &gt;= &amp;&amp; xhr.status &lt; 300) {


document.getElementById (' File_content_input '). innerHTML = Xhr.responsetext;


}


}


}


Xhr.open (' Get ', ' anfms.php?action=inputcontent&amp; ' +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 &gt;= &amp;&amp; xhr.status &lt; 300) {


document.getElementById (' file_get_content '). innerHTML = Xhr.responsetext;


}


}


}


Xhr.open (' Get ', ' anfms.php?action=getcontent&amp; ' +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 &gt;= &amp;&amp; xhr.status &lt; 300) {


document.getElementById (' File_make '). innerHTML = Xhr.responsetext;


}


}


}


Xhr.open (' Get ', ' anfms.php?action=filemake&amp; ' +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 &gt;= &amp;&amp; xhr.status &lt; 300) {


document.getElementById (' File_list '). innerHTML = Xhr.responsetext;


}


}


}


Xhr.open (' Get ', ' anfms.php?action=delete_file&amp;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 &gt;= &amp;&amp; xhr.status &lt; 300) {


document.getElementById (' File_list '). innerHTML = Xhr.responsetext;


}


}


}


Xhr.open (' Get ', ' anfms.php?action=delete_dir&amp;file= ' +file);


Xhr.setrequestheader ("If-modified-since", "0");


Xhr.send ();


}


&lt;/script&gt;


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 ' &lt;div class= ' file_list_t ' &gt; ';


$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 ' &lt;li&gt;&lt;a href= ' javascript:void (0); "onclick=" Javascript:file_list (". $path."); &gt; '. $file. ' &lt;/a&gt;&lt;/li&gt; ';


}


}else{


$path = $path 1. $file. ' /';


$path = Iconv (' gb2312 ', ' utf-8 ', $path);


if (Is_dir ($path 1 $file)) {


Echo ' &lt;li&gt;&lt;a href= ' javascript:void (0); "onclick=" Javascript:file_list (". $path."); &gt; '. $file. ' &lt;/a&gt;&lt;span&gt;&lt;a href= "javascript:void (0);" onclick= "Javascript:if (Confirm (' Confirm deletion ')) Dir_delete ('. $ Path. '); &gt; Delete &lt;/a&gt;&lt;/span&gt;&lt;/li&gt; ';


}else{


$file = Iconv (' gb2312 ', ' utf-8 ', $file);


$filesize = FileSize ($path 1 $file)/1000;


Echo ' &lt;li&gt; ' $file. '-('. $filesize. ' kb) &lt;span&gt;&lt;a href= "javascript:void (0);" onclick= "Javascript:if ( Confirm (' Confirm deletion? ')) File_delete ("$path 1. $file."); &gt; Delete &lt;/a&gt;&lt;/span&gt;&lt;/li&gt; ';


}


}


}


}


Closedir ($dir);


}


Echo ' &lt;/div&gt; ';


}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. ' &lt;br/&gt; ';


}


}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!= '. ' &amp;&amp; $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 ';


}


}


?&gt;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.