Web online File Manager learning notes and summaries (4) View file contents

Source: Internet
Author: User

② viewing the contents of a file

A. Obtaining the contents of the document through File_get_contents ($filename)

B. Display content through highlight_string ($string) or Highlight_file ($filename). Use PHP's built-in syntax highlighter to define colors, print output or return output, or return a syntax-highlighted version of PHP code

When you use file_get_contents to read (PHP) the contents of a file and display it on the page, you can use the contents of the <textarea></textarea> package output:

$content file_get_contents ($filename); Echo "<textarea cols= ' rows= ' >{$content}</textarea>";

index.php:

1<?PHP2 require' Dir.func.php ';3 require' File.func.php ';4 require' Common.func.php ';5 $path= ' file ';6 $info= Readdirectory ($path);7 8 $act= @$_request[' Act '];9 $filename= @$_request[' filename '];Ten //Jump Change Amount One $redirect= "index.php?path={$path}"; A if($act= = ' CreateFile '){ -     //Create a file -     $mes= CreateFile ($path.‘ /‘.$filename); theAlertmes ($mes,$redirect); -}Else if($act= = ' Showcontent '){ - //View File Contents -     $content=file_get_contents($filename); +     //echo "<textarea readonly= ' readonly ' cols= '" rows= ">{$content}</textarea>"; - //Highlight PHP code + //Highlight the PHP code in the string A     if(strlen($content)){ at     $newContent=highlight_string($content,true); -     //Highlight the PHP code in the file - //highlight_file ($filename); -     $str=<<<EOF -<table width= ' 100% ' bgcolor= ' Pink ' cellpadding= ' 5 ' cellspacing= "0" > -<tr> in<td>$newContent</td> -</tr> to</table> + EOF; -         Echo $str; the}Else{ *Alertmes ("The file has no content, please edit and view!") ",$redirect); $     }Panax Notoginseng } -?> the<! DOCTYPE html> + A the<meta charset= "UTF-8" > +<title>insert title here</title> -<link rel= "stylesheet" href= "Cikonss.css"/> $<link rel= "stylesheet" href= "Common.css"/> $ -<body> - the<div id= "Top" > -<ul id= "Navi" >Wuyi<li><a href= "index.php" title= "Home directory" ><span style= "MARGIN-LEFT:8PX; margin-top:0px; top:4px; "class= "icon Icon-small icon-square" ><spanclass= "Icon-home" ></span></span></a></li> the<li><a href= "#" onclick= "Show (' CreateFile ')" title= "New file" ><span style= "MARGIN-LEFT:8PX; margin-top:0px; top:4px; "class= "icon Icon-small icon-square" ><spanclass= "Icon-file" ></span></span></a></li> -<li><a href= "#" title= "new Folder" ><span style= "MARGIN-LEFT:8PX; margin-top:0px; top:4px; "class= "icon Icon-small icon-square" ><spanclass= "Icon-folder" ></span></span></a></li> Wu<li><a href= "#" title= "Upload file" ><span style= "MARGIN-LEFT:8PX; margin-top:0px; top:4px; "class= "icon Icon-small icon-square" ><spanclass= "Icon-upload" ></span></span></a></li> -<li><a href= "#" title= "Return to Parent directory" ><span style= "MARGIN-LEFT:8PX; margin-top:0px; top:4px; "class= "icon Icon-small icon-square" ><spanclass= "Icon-arrowleft" ></span></span></a></li> About</ul> $</div> -<form action= "index.php" method= "post" enctype= "Multipart/form-data" > -<table width= ' 100% ' border= ' 1 ' cellpadding= "5" cellspacing= "0" bgcolor= "#abcdef" align= "Center" > -<tr id= "CreateFolder" style= "Display:none;" > A<td> Please enter a folder name </td> +&LT;TD > the<input type= "text" name= "DirName"/> -<input type= "hidden" name= "path" value= "<?php Echo$path;? > "/> $<input type= "Submit" name= "Act" value= "Create folder"/> the</td> the</tr> the<tr id= "CreateFile" style= "Display:none;" > the<td> Please enter a file name </td> -&LT;TD > in<input type= "text" name= "filename"/> the<input type= "hidden" name= "path" value= "<?php Echo$path;? > "/> the<input type= "hidden" name= ' act ' value= ' createFile '/> About<input type= "Submit" value= "Create File"/> the</td> the</tr> the<tr id= "UploadFile" style= "Display:none;" > +&LT;TD > Please select the file to upload </td> -&LT;TD ><input type= "file" name= "MyFile"/> the<input type= "Submit" name= "Act" value= "upload file"/>Bayi</td> the</tr> the&LT;TR align= "center" > -<td> numbering </td> -<td> name </td> the<td> type </td> the<td> size </td> the<td> readable </td> the<td> writable </td> -<td> executable </td> the<td> creation Time </td> the<td> Modify Time </td> the<td> Access Time </td>94<td> Operations </td> the</tr> the<?PHP the         if($info[' File ']){98             $i= 1; About             foreach($info[' File '] as $val){ -                 $p=$path.‘ /‘.$val;101?>102&LT;TR align= "center" >103<td><?phpEcho $i;? ></td>104<td><?phpEcho $val;? ></td> the<td><?php$src=filetype($p) = = ' file '? ' File_ico.png ': ' Folder_ico.png ';? >$src;? > "title= ' Files ' ></td>106<td><?phpEchoTransbyte (filesize($p));? ></td>107<td><?php$src=is_readable($p)?‘ Correct.png ': ' Error.png ';? >$src;? > "width=" title= ' readable ' ></td>108<td><?php$src=is_writeable($p)?‘ Correct.png ': ' Error.png ';? >$src;? > "width=" title= ' writable ' ></td>109<td><?php$src=is_executable($p)?‘ Correct.png ': ' Error.png ';? >$src;? > "width=" title= ' writable ' ></td> the<td><?phpEcho Date(' Y-m-d h:i:s ',Filectime($p));? ></td>111<td><?phpEcho Date(' Y-m-d h:i:s ',Filemtime($p));? ></td> the<td><?phpEcho Date(' Y-m-d h:i:s ',Fileatime($p));? ></td>113<td> the<a href= "index.php?act=showcontent&filename=<?php Echo$p;? > "title= ' View ' ></a> the<a href= "" title= ' Modify ' ></a> the<a href= "" title= ' rename ' ></a>117<a href= "" title= ' Copy ' ></a>118<a href= "" title= ' Cut ' ></a>119<a href= "" title= ' delete ' ></a> -<a href= "" title= "Download ' ></a>121</td>122</tr>123<?PHP124                 $i++; the             }126         }127?> -</table>129</form> the<script src= ' Common.js ' ></script>131</body> theView Code

Web online File Manager learning notes and summaries (4) View file contents

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.