PHP Server File Manager Development Summary (IV): Using the session Response folder navigation

Source: Internet
Author: User
Tags change settings php server php session

On the back of the book, the first folder (home) icon next to the upper folder (up) and refresh the current folder (refresh) two icons, the corresponding image link is:

<li><a href= "#" title= "Up" onclick= "Onup ()" > </a></li> <li><a href= "#" title= "Refresh" onclick= "Onrefresh ()" ></a></li>

The corresponding event code is:

function Onrefresh () {var strdirname = "Refresh";    var strencodedname = Escape (strDirName);    $.post ("query.php", {act:strencodedname}, function (data) {$ (' #spanDirTable '). HTML (data); });}    function Onup () {var strdirname = "Back";    var strencodedname = Escape (strDirName);    $.post ("query.php", {act:strencodedname}, function (data) {$ (' #spanDirTable '). HTML (data); });}

As you can see, there is no folder path to jump at post, and the corresponding folder needs to be obtained according to the specific browsing context. Therefore, the server side needs to be able to get the folder path of the current browse. Fortunately, PHP has prepared a session for us. The PHP session variable is used to store information about a user's session or to change settings for a user session. The Session variable holds information that is single-user and can be used by all pages in the application.

Before you store user information in a PHP session, you must first start the session.

Note: the Session_Start () function must precede the

<?phpsession_start ();? >

It is important to note that if you deploy multiple pages and need to share PHP, each page will need to use Session_Start () at the beginning.

Use $_session to access session variables in PHP. Save the currently browsed folder after you output the folder contents list in the previous section:

if ($isDirContentView) {echo createdircontenttable ($strDirName);    $_session["Currdir"] = $strDirName; }

In this way, the $strdirname is saved to $_session["Currdir".

The following code responds to the action of refreshing the contents of the folder:

            case  "Refresh":                  $isDirContentView  =  true;                if  ( Isset ($_session["Currdir"))                   {                      $strDirName  = $_session["Currdir"];                 }                 else  $strDirName  =  "Home";                 break;

If the current folder is saved, navigate to the current folder, otherwise jump to the default first folder "/home"

The following code responds to the action of returning to the previous-level folder:

            case  "Back":                  $isDirContentView  =  true;                if  ( Isset ($_session["Currdir"))                   {                      $strDirName  = $_session["Currdir"];                      $strDirName  = rtrim ($strDirName,  "/");                      $listDir  = explode ("/",  $strDirName);                      $nBackLength  =  strlen (End ($listDir));                      $strDirName  = substr ($strDirName,  0, 0-$ Nbacklength);                     if  ($strDirName  ==  ")   $strDirName  = "/home ";                 }                 else  $strDirName  =   "/Home";                 Break

The last-level directory name is obtained by parsing the string and is limited to/home.

In addition, the front end can be implemented by jquery to preload the first folder content when the Web page opens:

$ (document). Ready (function () {onhome ();});

That is, when the page is loaded, execute the Onhome () function.

This article is from the "Accplayer Small Place" blog, make sure to keep this source http://accplaystation.blog.51cto.com/9917407/1614658

PHP Server File Manager Development Summary (IV): Using the session Response folder navigation

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.