#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Thumbs up How to Open & Edit file in List Content of Directory.


    Hello Everyone, Iím having a page php have function list content of directory in computer such as c:/folder after that I can open, write and save any file I want in list file. Now I have complete to list content of directory, now I want to click any file in list file of derectory to open in a textarea under list content of drictory to view and edit file, then I have a button submit to save it. I donít know how to do it so please fix my code I give under introduce me some example demo code or document to reference. Please help me. Thank very much.
    Here is my code:
    https://www(dot)mediafire(dot)com/?19123qkmgmf7toj
    Example picture about page equivalent and similar:
    In this picture it have list file.
    http://i1095(dot)photobucket(dot)com/albums/i472/OLAKEN91/f1_zpsd8327c90.jpg
    Now we can click to open 1 file such as ďextensions.confĒ to read, write and save it by button submit (update)
    http://i1095(dot)photobucket(dot)com/albums/i472/OLAKEN91/f2_zpsf48caae7.jpg

    P/s: I'm very sorry that new User have don't permit to post link
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Thumbs up


    Who known ? Please give me some answer?
  4. #3
  5. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    The best way to get a reply is to actually post your code in this thread instead of giving us a link to go download it.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Thumbs up


    Because it have many file such as javascirpt, index file, control file, config file so I have post link.
    Below here is code:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
    	table
    	{
    		width: 100%;
    		padding: 5px 5px 0px 5px;
    		text-decoration:none;
    	}
    	a
    	{
    		text-decoration:none;
    	}
    	h3
    	{
    		padding: 5px 0px 5px 0px;
    		color:#000;
    	}
    	tr
    	{
    		height: 20px;
    	}
    </style>
    </head>
    
    <body>
    <!--code show file cua thu muc-->
    <?php
    		echo "<h3>LIST FILE OF FOLDER</h3>";
    		// directory
    		$dir = "";
    		
            // Opens directory
            $myDirectory=opendir(".");
            
            // Gets each entry
            while($entryName=readdir($myDirectory))
    		{
    			$dirArray[]=$entryName;
            }
    		
    		// Finds extensions of files
            function findexts ($filename) 
    		{
    			$filename=strtolower($filename);//chuyen sang chu thuong
              	$exts=split("[/\\.]", $filename);//cat chuoi
              	$n=count($exts)-1;
              	$exts=$exts[$n];
              	return $exts;
    		}
    		 
    		// Closes directory
            closedir($myDirectory);
            
            // Counts elements in array
            $indexCount=count($dirArray);
            
            // Sorts files
            sort($dirArray);
            
    		// Print list content directory
    		print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
    		print("<TR><TH>Name</TH><th>Type</th><th>Size</th><th>Date Modified</th></TR>\n");
    		// Loops through the array of files
            for($index=0; $index < $indexCount; $index++)
    		{
    			if (substr("$dirArray[$index]", 0, 1) != ".")
    			{		
    				//File name
    				$name=$dirArray[$index];
    				$namehref=$dirArray[$index];
    				
    				// Gets File Extensions 
              		$extn=findexts($dirArray[$index]);
    				
    				// File type
    				switch ($extn)
    				{
    					case "png": $extn="PNG Image"; break;
    					case "jpg": $extn="JPEG Image"; break;
    					case "bmp": $extn="BITMAP Image"; break;
    					case "gif": $extn="GIF Image"; break;
    					case "ico": $extn="Windows Icon"; break;
    					case "txt": $extn="Text File"; break;
    					case "log": $extn="Log File"; break;
    					case "htm": $extn="HTML File"; break;
    					case "php": $extn="PHP Script"; break;
    					case "js": $extn="Javascript"; break;
    					case "css": $extn="Stylesheet"; break;
    					case "pdf": $extn="PDF Document"; break;
    					case "zip": $extn="ZIP Archive"; break;
    					case "docx": $extn="Microsoft Word Document"; break;
    					case "mp3": $extn="MP# Format Sound"; break;
    					default: $extn=strtoupper($extn)." File"; break;
              		}
              
              		// Gets file size 
              		$size=number_format(filesize($dirArray[$index]))."&nbsp"."KB";
              
              		// Gets Date Modified Data
              		$modtime=date("M j Y g:i A", filemtime($dirArray[$index]));
              		$timekey=date("YmdHis", filemtime($dirArray[$index]));
    				
    				print("
              		<tr>
                	<td><a href='./$namehref'>$name</a></td>
                	<td><a href='./$namehref'>$extn</a></td>
               	 	<td><a href='./$namehref'>$size</a></td>
                	<td sorttable_customkey='$timekey'><a href='./$namehref'>$modtime</a></td>
              		</tr>");
    				/*print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
    				print("<td>");
    				print(findexts($dirArray[$index]));
    				//print(filetype($dirArray[$index]));
    				print("</td>");
    				print("<td>");
    				print(filesize($dirArray[$index]));
    				print("</td>");
    				print("<td>");
    				print($modtime);
    				print("</td>");				
    				print("</TR>\n");*/
    			}
    		}
    		print("</TABLE>\n");
    ?>
    <!--code doc sua va luu 1 file bat ky-->
    		<br />
    		<h3>OPEN, EDIT AND SAVE ANY FILE IN LIST FILE OF FOLDER</h3>
    		<br />
            <form name="read_form" method="post" action="">
            <textarea name="read_file" cols="110" rows="35" wrap="off">
            </textarea>
            <br />
            <input type="submit" name="update" value="UPDATE" />
            </form>
    </body>
    </html>
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Thumbs up


    I still don't know how to when I click to file name in list content of directory, it content have show in textarea, what event click to to it ? I have read a example simple below but it open and save file have direct directory.
    Code:
    <?php
    
    $filename = isset($_GET['file']) ? $_GET['file'] : '';
    $directory = ("c:/folder/file.php"); // Restrict to this directory...
    
    $fn = $directory . $filename;
    
    if (isset($_POST['content']))
    {
        $content = stripslashes($_POST['content']);
        $fp = fopen($fn,"w") or die ("Error opening file in write mode!");
        fputs($fp,$content);
        fclose($fp) or die ("Error closing file!");
    }
    
    ?>
    
    <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
        <textarea rows="25" cols="100" name="content"><?php readfile($fn); ?></textarea>
        <hr />
        <input type="submit" value="Save">
    </form>
    Here is my project https://www(.)mediafire(.)com/?l3go25zl88359zu

IMN logo majestic logo threadwatch logo seochat tools logo