[李景山php]每天laravel-20160911|FileSystem-2
2016-07-12 08:49
579 查看
/** * Get the returned value of a file. * * @param string $path * @return mixed * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function getRequire($path) { if ($this->isFile($path)) {// if it is a file return require $path; // require it } throw new FileNotFoundException("File does not exist at path {$path}");// throw Exception } // yesterday we learn this filesystem function // now we will get the return value of a file. /** * Require the given file once. * * @param string $file * @return mixed */ public function requireOnce($file) { require_once $file;// fool }// require once a wrap by function /** * Write the contents of a file. * * @param string $path * @param string $contents * @param bool $lock * @return int */ public function put($path, $contents, $lock = false) { return file_put_contents($path, $contents, $lock ? LOCK_EX : 0); }// use a put function to set a normal function // and determine a if has a file write lock /** * Prepend to a file. * * @param string $path * @param string $data * @return int */ public function prepend($path, $data) { if ($this->exists($path)) { return $this->put($path, $data.$this->get($path)); }// if has old data, get it and combine it and new data return $this->put($path, $data); }// prepend is like insert some thing before the old data. /** * Append to a file. * * @param string $path * @param string $data * @return int */ public function append($path, $data) { return file_put_contents($path, $data, FILE_APPEND); }// append can use this file_put_contents function and set this variable to get it. /** * Delete the file at a given path. * * @param string|array $paths * @return bool */ public function delete($paths) {// use a very good way to delete a file ,but we need know this file path $paths = is_array($paths) ? $paths : func_get_args();// if paths is a array $success = true;// set this flag for done foreach ($paths as $path) {// loop this path try { if (! @unlink($path)) {// delete the file $success = false; } } catch (ErrorException $e) {// catch some thing wrong $success = false; } } return $success;// return result; } /** * Move a file to a new location. * * @param string $path * @param string $target * @return bool */ public function move($path, $target) { return rename($path, $target); }// a wrap like move use this rename
相关文章推荐
- 操作系统的ContentProvider 读写联系人
- php实现session入库操作例子
- output元素的追加和表单的验证
- Thinkphp中自动验证function和callback的区别
- [php入门] 4、HTML基础入门一篇概览
- PHP String方法归纳总结
- 总结PHP常使用的知识点解答
- PHP中发起异步请求
- php://input
- 隐藏PhpMyAdmin中的默认表
- php新玩具:psysh
- 用五种以上的方式调试php
- 编写php扩展(二)构建扩展中的函数的说明之PHP扩展开发及内核应用之阅读笔记(一)
- 2016/07/11 PHP接口的介绍与实现
- contentProvider
- ContentProvider如何获取联系人
- vsftpd
- PHP检测移动设备类mobile detection使用实例
- Laravel请求和输入
- PHP几个防SQL注入攻击自带函数区别