谁能告诉我macao我的世界游戏规则指令,每次去我都看不懂,谢谢指教

\ 我自己写的文件目录操作的类,谢谢指教
我自己写的文件目录操作的类,谢谢指教
PHP开发工程师
用汗水铸造辉煌!!!
作者的热门手记
*开源项目:所有关于文件目录操作的功能
*操作1:文件上传功能
*操作2:文件下载
*操作3:查看单级目录结构
*操作4:递归查看目录结构
*操作5:查看文件或文件夹的大小
*操作6:按关键字递归查找文件
*操作7:递归删除非空目录
*操作8:递归删除空目录
*操作9:递归创建目录
*操作10:剪切目录或文件
class File{
*@param $file array 要上传的文件数组信息
*@param $allow array 允许上传的文件类型
*@param $size int 允许上传文件的大小
*@param $path string 上传文件保存的路径
*@return $fileName string 文件上传成功后的新文件名
public function upload($file,$allow,$size,$path='./upload'){
//判断上传文件是否是一个合理的文件
if(!is_array($file)){
echo '上传文件不是一个合理的文件';
//判断上传文件是否是允许上传文件的类型
if(!in_array($file['type'],$allow)){
echo '不允许上传的文件类型';
//判断上传文件的大小是否符合允许上传文件的大小
if($file['size']&$size){
echo '上传文件大小超过允许上传文件大小';
//判断文件是否是通过HTTP POST上传的
if(!is_uploaded_file($file['tmp_name'])){
echo '文件不是通过http上传的';
//文件上传错误判断
if($file['error']&0){
switch($file['error']){
echo '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值';
echo '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值';
echo '文件只有部分被上传';
echo '没有文件被上传';
echo '找不到临时文件夹';
echo '文件写入失败';
//判断上传文件保存路径是否存在
if(!file_exists($path)){
mkdir($path);
//生成新的文件名
$newName = $this-&getNewFileName($file['name']);
if(move_uploaded_file($file['tmp_name'],$path.'/'.$newName)){
return $newN
echo '文件上传失败';
*@param $filePath string 要下载的文件的路径
public function downLoad($filePath){
$basename = basename($filePath);
header("Content-Type:application/octet-stream");
header("Content-Disposition:filename=".$basename);
echo file_get_contents($filePath);
*生成新的文件名
*@param $oldName string 旧的文件名
*@return $newName string 新的文件名
public function getNewFileName($oldName){
$newName = '';
//获取文件的后缀名
$ext = pathinfo($oldName)['extension'];
//生成六位随机数
$chars = array_merge(range('a','z'),range('A','Z'));
//打乱数组的顺序
shuffle($chars);
$newName .= implode(array_slice($chars,0,6),'');
$newName .= time();
$newName .= '.'.$
return $newN
*查看单级目录结构
*@param $path string 要查看的目录路径
*@param $arr array 目录结构
public function showDiretory($path){
$arr = array();
//判断路径是否存在
if(!file_exists($path)){
echo '文件或目录不存在';
if(is_dir($path)){
$handle = opendir($path);
while(false !== $file = readdir($handle)){
$subPath = $path . '/' . $
if(is_dir($subPath)){
$arr['dir'][] = $
$arr['file'][] = $
closedir($handle);
$arr['file'][] = basename($path);
*递归查看目录结构
*@param $path string 目录路径
*@return $arr array 目录结构
public function showDiretorys($path){
static $arr = array();
//判断路径是否存在
if(!file_exists($path)){
echo '文件或目录不存在';
if(is_dir($path)){
$handle = opendir($path);
while(false !== $file = readdir($handle)){
$subPath = $path . '/' . $
$subPath = str_replace('//','/',$subPath);
if($file=='.'||$file=='..'){
if(is_dir($subPath)){
$this-&showDiretorys($subPath);
$arr[dirname($subPath)][] = $
if($flag){
$arr[$path] =
closedir($handle);
$arr[] = $
*查看文件或文件夹的大小
*@param $path string 要查看大小的文件或目录路径
*@return $size float 文件或目录的大小
public function dirSize($path){
static $size = 0;
//判断文件或目录是否存在
if(!file_exists($path)){
echo '文件或目录不存在';
if(is_dir($path)){
$handle = opendir($path);
while(false !== $file = readdir($handle)){
$subPath = $path . '/' . $
if($file=='.'||$file=='..'){
if(is_dir($subPath)){
$this-&getSize($subPath);
$size += filesize($subPath);
closedir($handle);
return filesize($path);
return $this-&getSize($size);
*返回带有单位的文件大小
*@param $size int 原始的文件大小
*@return $hsize float 带有单位的文件大小
public function getSize($size){
$arr = array('Byte','KB','MB','GB','TB');
while($size&1024){
$size /= 1024;
$hsize = round($size,2);
$hsize .= $arr[$i];
*按关键字递归查找文件
*@param $path string 要查找文件的目录
*@param $keyword string 要查找的关键字
*@return $files array 查找到的文件数组
public function findFilesByKeyword($path,$keyword){
static $files = array();
//判断文件或目录是否存在
if(!file_exists($path)){
echo '文件或目录不存在';
if(is_dir($path)){
$handle = opendir($path);
while(false !== $file = readdir($handle)){
$subPath = $path . '/' . $
$subPath = str_replace('//','/',$subPath);
if($file=='.'||$file=='..'){
if(is_dir($subPath)){
$this-&findFilesByKeyword($subPath,$keyword);
if(strpos($file,$keyword)!==false){
$files[] = $subP
closedir($handle);
*递归删除非空目录
*@param $path string 要删除的目录
public function deleteDir($path){
//判断目录是否存在
if(!file_exists($path)){
echo '文件或目录不存在';
if(is_dir($path)){
$handle = opendir($path);
while(false !== $file = readdir($handle)){
if($file=='.'||$file=='..'){
$subPath = $path . '/' . $
if(is_dir($subPath)){
$this-&deleteDir($subPath);
unlink($subPath);
closedir($handle);
if(rmdir($path)){
echo '删除失败';
unlink($path);
*递归删除空目录
*@param $path string 要删除的目录路径
public function deleteEmptyDir($path){
//判断目录路径是否存在
if(!file_exists($path)){
echo '文件或目录不存在';
if(is_dir($path)){
$handle = opendir($path);
while(false !== $file = readdir($handle)){
if($file=='.'||$file=='..'){
$subPath = $path . '/' . $
if(is_dir($subPath)){
$this-&deleteEmptyDir($subPath);
closedir($handle);
if($flag){
if(rmdir($path)){
*递归创建目录
*@param $path string 在此目录下创建目录
*@param $destination string 创建的目标目录
public function makeDir($path,$destination){
$destination = str_replace('\\','/',$destination);
//判读目录是否存在
if(!file_exists($path)){
echo '目录不存在';
if(is_dir($path)){
$handle = opendir($path);
$dirs = explode('/',$destination);
$subPath = $path . '/' . $dirs[0];
if(!file_exists($subPath)){
if(!mkdir($subPath)){
echo '目录创建失败';
if(count($dirs)&1){
$dir = implode('/',array_slice($dirs,1));
$this-&makeDir($subPath,$dir);
closedir($handle);
*剪切目录或文件
*@param $source string 源文件或目录路径
*@param $destination string 目标文件或目录路径
public function moveDirToDestination($source,$destination){
//判断目录或者文件是否存在
if(!file_exists($source)||!file_exists($destination)){
echo '文件或目录不存在';
if(strpos($destination,$source)===0){
echo '目标目录是源目录的子目录';
$sourceDirs = $this-&showDiretorys($source);
$sourceDir = array_keys($sourceDirs);
$sourcePrev = substr($source,0,strrpos($source,'/')+1);
$subSourceDirs = array();
foreach($sourceDir as $key=&$val){
$subSourceDirs[$key] = ltrim($val,$sourcePrev);
//在目标目录中创建源目录中相应的目录
foreach($subSourceDirs as $val){
$this-&makeDir($destination,$val);
//复制文件
foreach($sourceDirs as $key=&$val){
foreach($val as $v){
//源文件路径
$fileSourcePath = $key.'/'.$v;
//目标文件路径
$fileDestinationPath = $destination.'/'.ltrim($fileSourcePath,$sourcePrev);
copy($fileSourcePath,$fileDestinationPath);
//删除原目录
$this-&deleteDir($source);
header('content-type:text/charset=utf-8');
$fileObj = new File();
$dirs = $fileObj-&moveDirToDestination('./777','./000');
//$dirs = $fileObj-&deleteDir('./huhu');
echo '&pre&';
var_dump($dirs);
相关标签:
请登录后,发表评论
评论(Enter+Ctrl)
评论加载中...
评论加载中...
Copyright (C)
All Rights Reserved | 京ICP备 号-2(Reverona)
(罗小贱三世)
(love octopus)
第三方登录:图中第四个字是什么,我看不懂。 大神指教。 谢谢-
你正在浏览: &>&
图中第四个字是什么,我看不懂。 大神指教。 谢谢_
图中第四个字是什么,我看不懂。 大神指教。 谢谢5分
所以写的是12月23日这是中国表达农历日期的字;二十&quot,表示&quot。在日历的阴历日期里差
应该是写错了,正确写法是廿,这句话的意思是十二月二十三日,指的是农历,在中国的农历里廿是代表二十的意思
这个字读(nian第四声)表示20的意思!!!
廿,nian三声,二十的意思
是二十的意思
求解图中的四个字念什么啊。。。 [
坐吃山空? 解释:只坐着吃,山也要空。指光是消费而不从事生产,即使有堆积如山的财富,也要耗尽。 拼音...]图中四个文字写的是什么 [
——“康熙年制” 读法: 年 康 制 熙]图中第四个字是什么,我看不懂。 大神指教。 谢谢 [
这是中国表达农历日期的字,表示&二十&所以写的是12月23日。在日历的阴历日期里差。]请问图片上那四个字是什么字? [
状元及第]这张图片第四个字是什么字?这张图片是什么意思? [
这都不知道——被禁闭了呗(关呀不就是禁吗)]图上四个字是什么字 [
天冠佳处]求图上四个字是什么字? [
您好 金文笔法摹写甲骨文。 释文右起:饮飨共舞 希望回答可以帮助您]请问图中的四个小字是什么字? [
管述 (束)丛主人]请问图片中的四个字是什么?代表什么意思 [
坐井观天?好像不是 这是哪来的题目?给点背景提示一下]}

我要回帖

更多关于 就不听指挥游戏规则 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信