PHP fopen文件名.是相对的还是绝对的? [英] PHP fopen filename. Is it relative or absolute?

查看:123
本文介绍了PHP fopen文件名.是相对的还是绝对的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在参考我的Web服务器的路径和fopen时遇到问题.

I'm having problems with my paths and fopen with reference to my web server.

我有一个文件保存在 public/dan/new/apps/lovescopes/thisfile.php 中.

I have a file saved in public/dan/new/apps/lovescopes/thisfile.php.

thisfile.php将使用fopen"x +"在 public/internalServer/lovescopes/xml/2009/12 中创建一个新文件.

thisfile.php will create a new file in public/internalServer/lovescopes/xml/2009/12 using fopen "x+".

现在我的错误显示在fopen所在的行:

Now my errors show in the line where fopen is:

  1. 如果我像../../../../internalServer/lovescopes/xml/2009/12那样以相对方式键入路径,则会出现权限被拒绝"错误.

  1. If I type in the path as relative like ../../../../internalServer/lovescopes/xml/2009/12 I end up with a Permission Denied error.

如果我输入诸如/public/internalServer/lovescopes/xml/2009/12之类的绝对路径,则最终结果为无法打开流:没有这样的文件或目录"

If I type an absolute path like /public/internalServer/lovescopes/xml/2009/12 I end up with "Failed to open Stream: No such File or Directory"

如果仍然要使用相对或绝对路径,我仍然会感到困惑.我有一个ftp_nlist,它与#2完美配合. Fopen一样吗?

I'm still confused if I should use relative or absolute paths. I have a ftp_nlist and it worked perfectly well with #2. Is Fopen the same?

还有我认为指向同一路径的不同错误消息,我不知道我在正确的1或2方向上做了什么?

Also with the different error messages which I believe points to the same path, I don't know which way am I doing it right 1 or 2?

推荐答案

为什么不使用use realpath()以及您的相对路径.

Why not use use realpath() with your relative paths.

权限被拒绝表示,您尝试访问的文件夹对网络服务器或运行PHP程序的任何用户都不可读和/或可写.

Also permission denied indicates that the folder you are trying access to is not readable and/or writable by the webserver or whatever user your PHP process runs under.

此外,如果要一次性读取/写入变量,请使用

In addition, if you want to read/write files in one go from/to a variable, you might want to use file_get_contents() and file_put_contents().

这篇关于PHP fopen文件名.是相对的还是绝对的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆