Code Monkey home page Code Monkey logo

directory's Introduction

directory

php下对于目录及目录下文件操作的工具

使用方法

目录及文件的创建

 $lmD = new Directory();
 $lmD->setBasePath('/usr/local/var/www/');
 $lmD->buildPath('img/a' , 0755);
 $lmD->buildPath('img/b' , 0755);
 $lmD->buildPath('img/c' , 0755);
 $lmD->buildFile('img/a/a.txt' , 0755);
 $lmD->buildFile('img/b/b.txt' , 0755);
 $lmD->buildFile('img/c/c.txt' , 0755);
 $lmD->removeDirs('img/' , ['a']);//img目录下除了a以外其他全部删除掉

上述代码执行后会产生一个/usr/local/var/www/img/a/a.txt文件,b.txt和c.txt存在过,但之后被删除了。

文件的打开与写入

$time = time();
$date = date('YmdH' , $time);
$fileName = 'tmp' . $time  . rand(100 , 999). '.html';
$directory =  new Directory();
$directory->file = new File();
$directory->setBasePath(Yii::getAlias('@vendor') . '/liumapp/dompdf/www/data');
$directory->buildPath($date);
$directory->buildFile($date . '/' . $fileName);
$directory->file->setFileName($directory->getAbsolutPath($date . '/' . $fileName));

$string = 'this is the one must be done';
$directory->file->open()->write($string);

上述代码执行后会产生一个/usr/local/var/www/vendor/liumapp/dompdf/www/data/2017091402/tmp1491356100.html的文件,文件内容是'this is the one you must be done'.

directory's People

Contributors

liumapp avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.