Phar存档没有Symfony文件系统的读写权限

编程入门 行业动态 更新时间:2024-10-24 11:12:42
本文介绍了Phar存档没有Symfony文件系统的读写权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个cli应用程序,该应用程序尝试使用symfony 3 fileSystem组件创建文件.一切正常,但是如果我将应用程序放在phar存档中,symfony无法写入该文件.

i have created a cli app which tries to create a file with symfony 3 fileSystem component. All works fine, but if i put the app in a phar archive symfony can't write the file.

这是我创建phar存档的方式:

This is how i created the phar archive:

<?php $phar = new Phar('app.phar', 0, 'app.phar'); $phar->buildFromDirectory(dirname(__FILE__) ); $phar->setStub($phar->createDefaultStub('app.php'));

app.php调用symfony文件系统组件:

The app.php call the symfony filesystem component:

<?php .... $this->fileSystem->dumpFile( 'testfile.txt', 'my test content' );

如果我直接执行app.php,这很好.但是,如果我将其作为.phar执行,则会收到此消息.

This works fine if i execute app.php directly. But if i execute it as a .phar i get this message.

[Symfony\Component\Filesystem\Exception\IOException] Failed to create ".": mkdir(): File exists.

其他操作,例如echo正常运行. 我认为,phar存档的IO操作存在问题.但是我不理解问题出在哪里.在我的php.ini中,配置了phar.readonly = Off.

Other operations like echo working fine. In my opinion i think, that the phar archive has a problem with IO operations. But i don't unterstand whats the problem. In my php.ini is phar.readonly=Off configured.

我希望有人能给我提示. :)

I hope someone can give me a hint. :)

推荐答案

Phar具有不同的路径结构,而symfony方法确实具有dirname($filename); github/symfony/symfony/blob/master/src/Symfony/Component/Filesystem/Filesystem. php#L679

Phar's have a different path structure, and that symfony method does dirname($filename); github/symfony/symfony/blob/master/src/Symfony/Component/Filesystem/Filesystem.php#L679

尝试定义完整路径.

$path = '.'; if (!empty($pharPath = \Phar::running(false))) { $path = dirname($pharPath); } $this->fileSystem->dumpFile( $path.'/testfile.txt', 'my test content' );

更多推荐

Phar存档没有Symfony文件系统的读写权限

本文发布于:2023-06-04 08:35:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/493357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件系统   权限   Phar   Symfony

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!