The process of directory establishment, deletion, file uploading and deletion on the server

Source: Internet
Author: User
Tags chmod copy create directory file copy strcmp file permissions
Process | Upload <?php
Extract ($_post);
Extract ($_get);

?>
<title> View server-side directories and files </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">

<body bgcolor= "#FFFFFF" text= "#000000" >
<form name= "Form1" method= "Post" action= "<?php Echo $_server[php_self];?>" >
<font color= "#006633" > enter directory Name: </font>
<input type= "text" name= "Inputdirroot" value= "<?= $InputDirRoot?>" >
<input type= "Submit" name= "Submit" value= "View this directory content" >
</form>
<form name= "Form1" method= "Post" action= "<?php Echo $_server[php_self];?>" >
<input Type=hidden name= "method" Value= "Createdir" >
<font color= "#006633" > enter directory Name: </font>
<input type= "text" name= "InputDir" value= "<?= $InputDirRoot?>" >
<input type= "Submit" name= "submit" value= "Build Catalogue" >
</form>
<form name= "Form1" method= "Post" action= "<?php Echo $_server[php_self];?>" enctype= "Multipart/form-data" >
<input Type=hidden name= "method" Value= "UploadFile" >
<font color= "#006633" > Upload directory Name: </font>
<input type= "text" name= "InputDir" value= "<?= $InputDirRoot?>" >
<font color= "#006633" > Please select File: </font>
<input type= "File" name= "UploadFile" >
<input type= "Submit" name= "submit" value= "Upload file" >
</form>
<form name= "Form1" method= "Post" action= "<?php Echo $_server[php_self];?>" >
<input Type=hidden name= "method" value= "Drop" >
<font color= "#006633" > Please enter: </font>
<input type= "text" name= "Info" value= "<?= $InputDirRoot?>" >
<input type= "Submit" name= "submit" value= "Delete file/directory" >
</form>
<?php
$n = 0;
if (Isset ($InputDirRoot))
{
$handle =opendir ($InputDirRoot);
echo Directory list: <font color= #FF0000 > ". $InputDirRoot." </font><br>while ($file = Readdir ($handle))
{
$n + +;
if (Is_dir ($InputDirRoot.) /". $file))
$file = "<a href=\" $_server[php_self]? inputdirroot= $InputDirRoot/$file \ "><font color= #006600 >[". $file. "] </font></a> ";
Else
$file = "<a href=\" typefile.php?filename= $InputDirRoot/$file \ Target=_blank><font color= #993300 >. $ File. " </font></a> ";
echo "". $file. " <br> ";
}
Closedir ($handle);
}

if (Isset ($method) && isset ($InputDir) && strcmp ($method, "Createdir") ==0) {//Create directory
if (Is_dir ($InputDir)) {
chmod ($InputDir, 0777);
echo "Directory already exists! Permission modification complete! ";
}else{
if (@mkdir ("$InputDir")) {
echo "Directory established ...!";
}else{
echo "Directory Build failed ...!";
}
chmod ($InputDir, 0777);
}
}

if (Isset ($method) && isset ($InputDir) && strcmp ($method, "UploadFile") ==0) {//uploading or deleting files
if (Is_file ($InputDir.) /". $_files[uploadfile][name])" {
chmod ($InputDir. " /". $_files[uploadfile][name],0777);
echo "File exists! Deleted!--You can upload file again ";
Unlink ($InputDir. " /". $_files[uploadfile][name]);
}else{
if (@copy ($_files[uploadfile][tmp_name), $InputDir. " /". $_files[uploadfile][name])" {
echo "file {$_files[uploadfile][name]} is correctly copied to {$InputDir} ...!";
}else{
echo "File copy failed ...!";
}
chmod ($InputDir. " /". $_files[uploadfile][name],0777);
}
}

if (Isset ($Info) && strcmp ($method, Drop) ==0) {//delete file or directory
if (Is_dir ($Info)) {
if (RmDir ($Info)) {
echo "Directory {$Inof} delete complete";
}else{
The echo directory cannot be deleted! Cause--maybe there are files in the directory! ";
}
}
if (Is_file ($Info)) {
if (unlink ($Info)) {
echo "File {$Info} deleted ...!"
}else{
Echo ' file {$Info} deletion failed ...! Attempt to modify file permissions delete ... ";
if (chmod ($Info, 0777)) {
Unlink ($Info);
echo "File {$Info} permissions modified after deletion ...";
}else{
The echo file {$Info} cannot be deleted by the Web, possibly with FTP permissions set on this file ... ";
}
}
}
}

echo "echo "Total $n items."
?>
</body>


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.