① Creating a file
A. Legality of file name: cannot contain \/:* "<>| and other special characters
B. Detect if there is a file with the same name in the current directory, if prompted, rename it, create it if it does not exist, create it directly
index.php:
<?PHPrequire' Dir.func.php ';require' File.func.php ';require' Common.func.php ';$path= ' file ';$info= Readdirectory ($path);$act= @$_request[' Act '];$filename= @$_request[' filename '];//Jump Change Amount$redirect= "index.php?path={$path}";if($act= = ' CreateFile '){ //Create a file $mes= CreateFile ($path.‘ /‘.$filename); Alertmes ($mes,$redirect);}? ><! DOCTYPE html>class= "icon Icon-small icon-square" ><spanclass= "Icon-home" ></span></span></a></li> <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> <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> </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;" > <td> Please enter a folder name </td> <td > <input type= "text" name= "DirName"/> <input type= "hidden" name= "path" value= "<?php Echo$path;? > "/> <input type=" submit "name=" Act value= "Create folder"/> </td> </tr> <tr Id= "CreateFile" style= "Display:none;" > <td> Please enter file name </td> <td > <input type= "text" name= "filename"/> <input type= "hidden" name= "path" value= "<?php Echo$path;? > "/> <input type=" hidden "name= ' act ' value= ' createFile '/> <input type=" Submit "value= "Create File"/> </td> </tr> <tr id= "UploadFile" style= "Display:none;" > <TD > Please select file to upload </td> <td ><input type= "file" name= "MyFile"/> <inp UT type= "submit" name= "Act" value= "upload file"/> </td> </tr> <tr align= "center" > & Lt;td> number </td> <td> name </td> <td> type </td> <td> size </td> <td> readable </td> <td> writable </td> <td> executable </td> <td> Create time </td> <td> modification Time </td> <td> access time </td> <td> action </td> </tr> <?PHPif($info[' File ']){ $i= 1; foreach($info[' File '] as $val){ $p=$path.‘ /‘.$val; ?> <tr align= "center" > <td><?phpEcho $i;? ></td> <td><?phpEcho $val;? ></td> <td><?php$src=filetype($p) = = ' file '? ' File_ico.png ': ' Folder_ico.png ';? >$src;? > "title= ' Files ' ></td> <td><?phpEchoTransbyte (filesize($p));? ></td> <td><?php$src=is_readable($p)?‘ Correct.png ': ' Error.png ';? >$src;? > "width=" title= ' readable ' ></td> <td><?php$src=is_writeable($p)?‘ Correct.png ': ' Error.png ';? >$src;? > "width=" title= ' writable ' ></td> <td><?php$src=is_executable($p)?‘ Correct.png ': ' Error.png ';? >$src;? > "width=" title= ' writable ' ></td> <td><?phpEcho Date(' Y-m-d h:i:s ',Filectime($p));? ></td> <td><?phpEcho Date(' Y-m-d h:i:s ',Filemtime($p));? ></td> <td><?phpEcho Date(' Y-m-d h:i:s ',Fileatime($p));? ></td> <td> <a href= "" title= ' View ' >< /a> <a href= "" title= ' Modify ' ></a> <a HRE f= "" title= ' rename ' ></a> <a href= "" title= ' Copy ' ><i MG src= "Images/copy.png" width= "+" ></a> <a href= "" title= ' Cut ' ></a> <a href=" "title= ' delete ' ></a> <a href= "" title= ' Download ' ></a> </td> < ;/tr> <?PHP$i++; } } ? ></table></form><script src= ' Common.js ' ></script></body>View CodeCommon.func.php Store Public methods:
<? PHP // Prompt for action information and jump function alertmes ($mes,$url) { echo "<script>alert (' {$ Mes} '); location.href= ' {$url} ';</script> ';}
View CodeCommon.js:
function Show (dis) { = ' block ';}
View Codefile.func.php:
<?PHP/*Convert byte size*/functionTransbyte ($size){ $arr=Array(' B ', ' KB ', ' MB ', ' GB ', ' TB ', ' EB ')); $i= 0; while($size> 1024){ $size/= 1024; $i++; } return round($size, 2). ' ‘.$arr[$i];}/*Create a file*//*Note: The Regular expression section in front of the CreateFile function uses the basename function, which filters out all/slashes. This allows any input/error in the file name. */ functionCreateFile ($filename){ //verify file name legitimacy, contains special characters \/: | * "? < > $pattern= '/[\/,\*,<,>,\?\|,\\\\,:, ']/';//* < > |?: "Valid if(!Preg_match($pattern,basename($filename))){ //detects if the current directory now has a file with the same name if(!file_exists($filename)){ //create a file with the touch method if(@Touch($filename)){ return' File creation succeeded '; }Else{ return' File creation failed '; } }Else{ return' File already exists, please rename and create '; } }Else{ return' Illegal file name '; }}
View Code② Viewing files
③ Modifying files
Reference:
Regular expression matching backslash: http://blog.csdn.net/longyulu/article/details/8294114
PHP matches backslash ' \ ' and USD ' $ ': http://www.oschina.net/code/snippet_583625_20448
Web online File Manager learning notes and summaries (3) creating files