本文整理汇总了PHP中Filesystem类的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem类的具体用法?PHP Filesystem怎么用?PHP Filesystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filesystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generatePDF
function generatePDF()
{
// tempfolder
$tmpBaseFolder = TEMP_FOLDER . '/shopsystem';
$tmpFolder = project() ? "{$tmpBaseFolder}/" . project() : "{$tmpBaseFolder}/site";
if (is_dir($tmpFolder)) {
Filesystem::removeFolder($tmpFolder);
}
if (!file_exists($tmpFolder)) {
Filesystem::makeFolder($tmpFolder);
}
$baseFolderName = basename($tmpFolder);
//Get site
Requirements::clear();
$link = Director::absoluteURL($this->pdfLink() . "/?view=1");
$response = Director::test($link);
$content = $response->getBody();
$content = utf8_decode($content);
$contentfile = "{$tmpFolder}/" . $this->PublicURL . ".html";
if (!file_exists($contentfile)) {
// Write to file
if ($fh = fopen($contentfile, 'w')) {
fwrite($fh, $content);
fclose($fh);
}
}
return $contentfile;
}
示例2: processThumb
public function processThumb($imgsrc, $_id, $isUrl = true)
{
$_id = empty($_id) ? $this->_id : $_id;
$storage = Yii::app()->params['feed_path'];
$temp = Yii::app()->params['temp'];
$fileInfo = explode('.', $imgsrc);
$fileType = $fileInfo[count($fileInfo) - 1];
$fileName = 'tmp_' . $_id . "." . $fileType;
$tmpFile = $temp . DS . $fileName;
if ($isUrl) {
$res_get_file = FileRemote::getFromUrl($imgsrc, $tmpFile);
} else {
$fileSystem = new Filesystem();
$res_get_file = $fileSystem->copy($imgsrc, $tmpFile);
}
if (file_exists($tmpFile)) {
$fileDest = StorageHelper::generalStoragePath($_id, $fileType, $storage);
/*$fileSystem = new Filesystem();
$copy = $fileSystem->copy($tmpFile,$fileDest);*/
$width = Yii::app()->params['profile_image']['thumb']['width'];
$height = Yii::app()->params['profile_image']['thumb']['height'];
$resizeObj = new ResizeImage($tmpFile);
$rs = $resizeObj->resizeImage($width, $height, 0);
$res = $resizeObj->saveImage($fileDest, 100);
if ($resizeObj) {
$feed = self::model()->findByPk(new MongoId($_id));
$fileDest = str_replace($storage, '', $fileDest);
$feed->thumb = $fileDest;
$res = $feed->save();
return $res;
}
} else {
throw new Exception("create file temp error!", 7);
}
}
示例3: beforeGetContentBody
protected function beforeGetContentBody()
{
$sn = time();
$i = 0;
$tmpFile = $temp = Yii::app()->params['temp'];
$storage = Yii::app()->params['feed_path'];
$cdn = Yii::app()->params['cdn_url'];
$contentParttern = $this->config['content_pattern'];
foreach ($this->html->find("{$contentParttern} img") as $e) {
$imgSrc = $e->src;
if (!empty($imgSrc)) {
$fileInfo = explode('.', $imgSrc);
$fileType = $fileInfo[count($fileInfo) - 1];
$fileName = 'tmp_' . $sn . $i . "." . $fileType;
$sfile = $tmpFile . DS . $fileName;
$res_get_file = FileRemote::getFromUrl($imgSrc, $sfile);
if ($res_get_file && file_exists($sfile)) {
$fileDest = StorageHelper::generalStoragePath($sn . $i, $fileType, $storage);
$fileSystem = new Filesystem();
$copy = $fileSystem->copy($sfile, $fileDest);
if ($copy) {
echo $fileDest . "\n";
$fileDestUrl = str_replace($storage, $cdn, $fileDest);
$fileDestUrl = str_replace(DS, "/", $fileDestUrl);
echo $fileDestUrl . "\n";
$e->src = $fileDestUrl;
echo 'replace file content success' . "\n";
} else {
echo 'replace file content error' . "\n";
}
}
$i++;
}
}
}
示例4: deleteTmpDir
protected function deleteTmpDir($testCase)
{
if (!file_exists($dir = sys_get_temp_dir() . '/' . Kernel::VERSION . '/' . $testCase)) {
return;
}
$fs = new Filesystem();
$fs->remove($dir);
}
示例5: render
public function render()
{
if (!empty($this->sPath)) {
$oFilesystem = new Filesystem();
$sFileContents = $oFilesystem->getFileContents($this->sPath);
return $this->processMarkdown($sFileContents);
}
return null;
}
示例6: testShouldMoveFilesThatNeedEspecialPermissions
public function testShouldMoveFilesThatNeedEspecialPermissions()
{
$filesystem = new Filesystem();
$file = '/app/tmp/file';
$target = '/system/root/';
$return = $filesystem->sysMove($file, $target);
$this->assertRegExp('/sudo mv -v/', $return);
$this->assertRegExp('/\\/app\\/tmp\\/file/', $return);
$this->assertRegExp('/\\/system\\/root\\//', $return);
}
示例7: processAvatar
public static function processAvatar($model, $source, $type = "artist")
{
try {
$fileSystem = new Filesystem();
$alowSize = Yii::app()->params['imageSize'];
$maxSize = max($alowSize);
$folderMax = "s0";
foreach ($alowSize as $folder => $size) {
// Create folder by ID
$fileSystem->mkdirs($model->getAvatarPath($model->id, $folder, true));
@chmod($model->getAvatarPath($model->id, $folder, true), 0755);
// Get link file by ID
$savePath[$folder] = $model->getAvatarPath($model->id, $folder);
if ($size == $maxSize) {
$folderMax = $folder;
}
}
// Delete file if exists
if (file_exists($savePath[$folder])) {
$fileSystem->remove($savePath);
}
if (file_exists($source)) {
list($width, $height) = getimagesize($source);
$imgCrop = new ImageCrop($source, 0, 0, $width, $height);
// aspect ratio for image size
$aspectRatioW = $aspectRatioH = 1;
if ($type == "video") {
$videoAspectRatio = Yii::app()->params['videoResolutionRate'];
list($aspectRatioW, $aspectRatioH) = explode(":", $videoAspectRatio);
}
$res = array();
foreach ($savePath as $k => $v) {
$desWidth = $alowSize[$k];
$desHeight = round($alowSize[$k] * intval($aspectRatioH) / intval($aspectRatioW));
if (file_exists($v) && is_file($v)) {
@unlink($v);
}
if ($width > 4000) {
self::ImageCropPro($v, $source, $desWidth, $desHeight, 70);
} else {
if ($k == $folderMax) {
$imgCrop->resizeRatio($v, $desWidth, $desHeight, 70);
} else {
$imgCrop->resizeCrop($v, $desWidth, $desHeight, 70);
}
}
}
if ($type != "video") {
$fileSystem->remove($source);
}
}
} catch (Exception $e) {
$error = $e->getMessage();
}
}
示例8: testIfRetrievingTheFilesWorks
public function testIfRetrievingTheFilesWorks()
{
$config = \Mockery::mock('eXistenZNL\\PermCheck\\Config\\Config');
$filesystem = new Filesystem($config, dirname(__FILE__));
$files = array(__FILE__);
$result = array();
foreach ($filesystem->getFiles() as $file) {
$result[] = $file->getPathname();
}
$this->assertEquals($files, $result);
}
示例9: manageConfigs
public function manageConfigs()
{
$fileSystem = new Filesystem();
$files = $fileSystem->files(__DIR__ . '/config');
if (!empty($files)) {
foreach ($files as $file) {
$name = explode('/', $file);
$this->mergeConfigFrom($file, str_replace('.php', '', $name[count($name) - 1]));
}
}
}
示例10: moveDefaultTemplate
private function moveDefaultTemplate()
{
$this->log('Moving default template...');
$fileDir = $this->container->getParameter('claroline.param.files_directory');
$defaultTemplate = $this->container->getParameter('claroline.param.default_template');
$newTemplateDir = $fileDir . '/templates';
$newTemplate = $newTemplateDir . '/default.zip';
$fs = new Filesystem();
$fs->mkdir($newTemplateDir);
$fs->copy($defaultTemplate, $newTemplate);
}
示例11: generalStoragePath
public static function generalStoragePath($objId, $fileType = 'jpg', $storage, $isUrl = false)
{
$year = date('Y');
$month = date('m');
$day = date('d');
$sep = $isUrl ? '/' : DS;
$exPath = $year . $sep . $month . $sep . $day;
$filePath = $storage . $sep . $exPath;
$fileSystem = new Filesystem();
$res = $fileSystem->mkdirs($filePath, '0755');
return $filePath . $sep . $objId . '.' . $fileType;
}
示例12: testIfRetrievingTheFilesWorks
public function testIfRetrievingTheFilesWorks()
{
/** @var Config|MockInterface $config */
$config = \Mockery::mock(new Config());
$filesystem = new Filesystem($config, __DIR__);
$files = array(__FILE__);
$result = array();
foreach ($filesystem->getFiles() as $file) {
$result[] = $file->getPathname();
}
$this->assertEquals($files, $result);
}
示例13: __construct
public function __construct($sConfigFile = 'config.json')
{
$oFilesystem = new Filesystem();
$sContents = $oFilesystem->getFileContents($sConfigFile);
if (!empty($sContents)) {
$this->_aConfig = json_decode($sContents, true);
if (empty($this->_aConfig)) {
throw new BadConfigException(sprintf($this->sError, $sConfigFile, $this->getJSONError(json_last_error())));
}
} else {
throw new BadConfigException("Config file is empty: " . $sConfigFile);
}
}
示例14: test_symlink_removal
public function test_symlink_removal()
{
$test_dir = 'tests/test-data/symlinks';
$test_link = $test_dir . '/points_nowhere';
if (is_dir($test_dir)) {
$this->rmdir_recursive($test_dir);
}
mkdir($test_dir);
symlink("does_not_exist", $test_link);
$fs = new Filesystem();
$fs->remove($test_dir);
$this->assertFalse(is_link($test_link) || is_file($test_link));
}
示例15: homeify
/**
* Replaces the `~` symbol with the user home path.
*
* @param string $path
* @return string The path with the `~` replaced with the user home path if any.
*/
public static function homeify($path, Filesystem $filesystem = null)
{
if (!is_string($path)) {
throw new \InvalidArgumentException('Paht must be a string');
}
if (empty($filesystem)) {
$filesystem = new Filesystem();
}
$userHome = $filesystem->getUserHome();
if (!(empty($userHome) && false !== strpos($path, '~'))) {
$path = str_replace('~', $userHome, $path);
}
return $path;
}