Home  >  Article  >  Backend Development  >  PHP code for the process of directory creation, deletion, file upload, and deletion on the server side_PHP tutorial

PHP code for the process of directory creation, deletion, file upload, and deletion on the server side_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:50:07739browse

extract($_POST);
extract($_GET);
?>


查看服务器端目录和文件





输入目录名:





输入目录名:





上传目录名:

请选择文件:





请输入:





$n = 0;
if (isset($InputDirRoot))
{
$handle=opendir($InputDirRoot);
echo "目录列表:".$InputDirRoot."

";
while ($file = readdir($handle))
{
$n ++;
if (is_dir($InputDirRoot."/".$file))
$file = "[".$file."]";
else
$file = "".$file."";
echo " ".$file."
";
}
closedir($handle);
}

if(isset($method) && isset($InputDir) && strcmp($method,"createdir")==0){//建立目录
if(is_dir($InputDir)){
chmod($InputDir,0777);
echo "目录已存在!权限修改完毕!";
}else{
if(@mkdir("$InputDir")){
echo "目录建立完毕...!";
}else{
echo "目录建立失败...!";
}
chmod($InputDir,0777);
}
}

if(isset($method) && isset($InputDir) && strcmp($method,"uploadfile")==0){//上传文件或删除文件
if(is_file($InputDir."/".$_FILES[UploadFile][name])){
chmod($InputDir."/".$_FILES[UploadFile][name],0777);
echo "文件存在!已经删除!--您可以重新上传文件";
unlink($InputDir."/".$_FILES[UploadFile][name]);
}else{
if(@copy($_FILES[UploadFile][tmp_name],$InputDir."/".$_FILES[UploadFile][name])){
echo "文件{$_FILES[UploadFile][name]}正确的拷贝到{$InputDir}内...!";
}else{
echo "文件拷贝失败...!";
}
chmod($InputDir."/".$_FILES[UploadFile][name],0777);
}
}

if(isset($Info) && strcmp($method,"drop")==0){//删除文件或目录
if(is_dir($Info)){
if(rmdir($Info)){
echo "目录{$Inof}删除完毕";
}else{
echo "目录无法删除!原因--可能是目录下还存在文件!";
}
}
if(is_file($Info)){
if(unlink($Info)){
echo "文件{$Info}删除完毕...!";
}else{
echo "文件{$Info}删除失败...!尝试修改文件权限删除...";
if(chmod($Info,0777)){
unlink($Info);
echo "文件{$Info}权限修改后删除完毕...";
}else{
echo "文件{$Info}无法通过WEB方式删除,可能是FTP权限对此文件有所设置...";
}
}
}
}

echo "
";
echo "总共 $n 项.";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319402.htmlTechArticle?php extract($_POST); extract($_GET); ? html head title View server-side directories and files /title meta http-equiv="Content-Type" content="text/html; charset=gb2312" /head body bgcolor=...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn