asgard/file
Composer 安装命令:
composer require asgard/file
包简介
README 文档
README
#File
File is a package to work with the file system and it provides a class to manipulate files as objects.
##Installation If you are working on an Asgard project you don't need to install this library as it is already part of the standard libraries.
composer require asgard/file 0.*
###$mode
When a method takes a parameter $mode, you can use different values:
$mode = \Asgard\File\FileSystem::OVERRIDE; #override existing files
$mode = \Asgard\File\FileSystem::RENAME; #rename new files
$mode = \Asgard\File\FileSystem::IGNORE; #ignore existing files
$mode = \Asgard\File\FileSystem::MERGEDIR; #merge directories
$mode = \Asgard\File\FileSystem::MERGEDIR | \Asgard\File\FileSystem::OVERRIDE; #merge directories but override existing files
$mode = \Asgard\File\FileSystem::MERGEDIR | \Asgard\File\FileSystem::RENAME; #merge directories but rename new files
$mode = \Asgard\File\FileSystem::MERGEDIR | \Asgard\File\FileSystem::IGNORE; #merge directories but ignore existing files
It defaults to OVERRIDE.
###Methods
Get relative path from a file to another:
\Asgard\File\FileSystem::relativeTo($from, $to);
Get a new filename if the existing one is already taken:
$filename = \Asgard\File\FileSystem::getNewFilename($filename);
Rename a file or directory:
$path = \Asgard\File\FileSystem::rename($src, $dst, $mode=null);
returns the new path if successful, otherwise false.
Copy a file or directory:
$path = \Asgard\File\FileSystem::copy($src, $dst, $mode=null);
returns the new path if successful, otherwise false.
Delete a file or directory:
\Asgard\File\FileSystem::delete($path);
returns true is successful, otherwise false.
Create a new directory:
\Asgard\File\FileSystem::mkdir($path);
returns true is successful, otherwise false.
Write content into a file:
\Asgard\File\FileSystem::write($path, $content, $mode=null, $append=false);
returns true is successful, otherwise false.
Instance:
$file = new \Asgard\File\File('/path/to/file.txt');
Set source:
$file->setSrc('/path/to/another/file.txt');
Set file name:
$file->setName('file2.txt');
Get file name:
$file->getName();
Check if the file was just uploaded:
$file->isUploaded();
Get the file size in bytes:
$file->size();
Get the file type:
$file->type();
Get the file extension:
$file->extension();
Check if the file exists:
$file->exists();
Get the file source:
$file->src();
Get the relative path to another file or directory:
$file->relativeTo('/another/file.jpg');
Move the to another directory:
$file->moveToDir('/a/dir/', $mode=null);
Check if the file is in a directory
$file->isIn('/a/dir/');
Check if the file is at a specific path:
$file->isAt('/path/to/file.txt');
Rename the file:
$file->rename('/anoter/path/to/file.txt', $mode=null);
Delete the file:
$file->delete();
Copy the file:
$file->copy('/path/to/copy.txt', $mode=null);
###Contributing
Please submit all issues and pull requests to the asgardphp/asgard repository.
License
The Asgard framework is open-sourced software licensed under the MIT license
asgard/file 适用场景与选型建议
asgard/file 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.54k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2014 年 07 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 asgard/file 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 asgard/file 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 5
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2014-07-16