Network Disk File Management

Source: Internet
Author: User

Using the file-related functions in PHP to manage a folder on the server, you can make simple file view and delete files and folders, add operations.

First, traverse the folder:

$fname = "Folder Path", while ($n = Readdir ($dir))                    //Traverse all files and folders in the folder {$url = $fname. " /". $n; if ($n! =". "&& $n! =" ... ") {if (Is_dir ($url)) {echo "<div class= ' file Mulu ' lj= ' {$url} ' >{$n}</div>";      If the folder displays a special color}else{echo "<div class= ' file ' lj= ' {$url} ' >{$n}  <input type= ' button ' value= ' delete ' lj= ' {$url} ' class= ' sc '/> </div> ";}}} Closedir ($dir);

 

Add the Create File button:

<input type= "text" id= "name"/><input type= "button" value= "new" id= "Newf"/>

  

Add a simple style:

CSS code:

*{margin:0px Auto; padding:0px}.file{width:50%; height:35px; line-height:35px; vertical-align:middle; border:1px Solid #63C; margin-top:2px;}. mulu{background-color: #63C; color:white}.prev{background-color: #F63; Color:white}

  

To add a click event, click on the folder to go to the next directory:

To introduce the JQ package:

$ (". Mulu"). DblClick (function () {var url = $ (this). attr ("LJ"); $.ajax ({url: "chuli.php", Data:{url:url},type: "POST", DataType: "TEXT", success:function (data) {window.location.href = "test.php";}})

  

Processing interface (chuli.php):

<?phpsession_start (); $url = $_post["url"];$_session["url"] = $url;

  

To add a Delete event:

$ (". SC"). Click (function () {var LJ = $ (this). attr ("LJ"); $.ajax ({url: "shanchu.php", Data:{lj:lj},type: "POST", DataType : "TEXT", success:function (data) {window.location.href = "test.php";}})

  

Processing interface (shanchu.php):

<?PHP$LJ = $_post["LJ"];unlink ($LJ);

  

To add a new file event:

$ ("#newf"). Click (function () {var name = $ ("#name"). Val (); $.ajax ({url: "xinjian.php", Data:{name:name},type: "POST", DataType: "TEXT", success:function (data) {window.location.href = "test.php";}})

  

Background processing interface: (xinjian.php):

<?phpsession_start (); $name = $_post["name"]; $url = $_session["url"]; $filename = $url. " /". $name; Touch ($filename);

  

At this point, the basic implementation of the function, but click on the folder into the next interface can not be returned, so to add the return button:

$JDLJ = Realpath ($fname), if ($JDLJ = = "d:\\wamp\\www\\1027") {}else{$fuji = dirname ($fname); echo "<div class=" file Prev ' lj= ' {$fuji} ' > Return to previous </div> ';}

  

$ (". Prev"). DblClick (function () {var url = $ (this). attr ("LJ"); $.ajax ({url: "chuli.php", Data:{url:url},type: "POST", DataType: "TEXT", success:function (data) {window.location.href = "test.php";}})

  

So click on the folder to return:

All code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

  

Network Disk File Management

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.