PHP 文件权限 - 创建文件
我正在创建一个幻灯片 WordPress 插件(尽管这并不是一个真正的 WordPress 问题)。通过各种设置,它通过 PHP 创建一个 CSS 文件,用于设置幻灯片的样式。
CSS 文件是根据用户保存到数据库的所有不同样式变量创建的,因此需要动态创建一个。
问题是,当 PHP 尝试保存创建的文件时,某些托管公司(或共享托管)会出现问题。一般来说,这些都是文件权限问题。阻止此文件保存会导致幻灯片显示不正确且出现故障。
对于有此类文件权限问题的用户,我可以通过 PHP 做些什么作为替代方案吗?据我所知,您可以通过 PHP 修改文件权限和文件所有权,但我个人以前从未这样做过,并且不确定正确的方法,但涵盖了尽可能多的不同场景。
对于很多用户来说,这只是告诉他们如何更改适当的文件权限,但对于少数用户来说,这完全超出了他们的能力范围,我不可能登录到那里的 FTP 并为他们做这件事(通常是这样)因为他们甚至不知道 FTP 是什么)。
有人能指出我正确的方向吗?
I'm in the process of creating a slideshow Wordpress plugin (although this isn't really a Wordpress question). Through all its various settings, it creates a CSS file through PHP that is used to style the slideshow.
The CSS file is created from all the different styling variables the user has saved to the database and hence the need to dynamically create one.
Problem is that some hosting companies (or shared hosting) cause problems when the PHP tries to save the created file. Generally these are file permission issues. Stopping this file from saving results in the slideshow not appearing correctly and malfunctioning.
Is there anything I can do through PHP as an alternative for users with such file permission issues? As far as I am aware you can modify file permissions and file ownership through PHP but I've personally never done it before and wouldn't really be sure about the right way to go about it yet cover as many different scenarios as possible.
For a lot of users it is simply a case of informing them on how to change the appropriate file permissions, but for the odd few this is completely beyond them and it's not possible for me to log into there FTP and do it for them (often because they wouldn't even know what FTP is).
Can anyone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你可能有一个目录,你可以在其中保存你的css文件并将其chmod到777,就像在php中这样:
我在这里看到的唯一问题是,拒绝你访问chmod你的文件的公司并不那么愚蠢给你的 php 留下这个权限...那么,为什么你不拥有一种“网关”文件来动态地从数据库中获取 css 值,形成有效的 css 输出并将其提供给用户呢?
I guess you could have a directory in which you would hold your css file(s) and chmod it to 777 like this in php:
The only problem I see here, that a company which denies you access to chmod your files is not that stupid to leave your php that permission... So, why don't you just have a kind of 'gateway'-file which will dynamically grab css values from DB, form a valid css output and serve it to the user?
您最好的选择可能是:
并将 PHP 文件作为样式表:
虽然这放弃了转储到 CSS 文件的“缓存”功能,但您当然可以利用通过 Wordpress 提供的任何缓存支持。不过,这种每次动态生成它的方法很可能不会导致瓶颈(无论如何,如果您担心的话)
Your best bet may be:
And point to the PHP file as a stylesheet:
While this foregoes the "caching" functionality of dumping to a CSS file, surely you could leverage whatever caching support is available through Wordpress. Likely though, this approach of dynamically generating it every time will not result in bottlenecking (profile anyway, if you're concerned)