2017-02-24 10:27
浏览 62

PhP fopen使用路径名创建文件

Trying to update a file file.xml, which is with folders dirA/dirB/dirC/file.xml where dirA is the current working dir. The file file.xml exists and has write permissions.

Using the following code works in local but on server it created a file by name "dirA\dirB\dirC\file.xml" outside dirA and saves into it

$file = fopen("dirA\dirB\dirC\file.xml", "w+")
fputs($file, $xmlFile);

Any idea why?

图片转代码服务由CSDN问答提供 功能建议

尝试更新文件 file.xml ,文件夹 dirA /dirB/dirC/file.xml 其中 dirA 是当前工作的目录。 文件file.xml存在且具有写权限。

使用以下代码在本地工作但在服务器上它创建了一个名为“dirA \ dirB \ dirC \ file.xml”的文件 dirA并保存到其中

  $ file = fopen(“dirA \ dirB \ dirC \ file.xml”,“w +”)
fputs($ file,$ xmlFile);  
 nclclose($ file); 


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dras2334 2017-02-24 10:31

    Maybe because you are running another environment on your server? Windows and Linux are a little bit itchy on their folders.

    You may also check if you have to use backslashes or not!

    Probably you also have to quote them:

    $file = fopen("dirA\/dirB\/dirC\/file.xml", "w+");
    点赞 打赏 评论

相关推荐 更多相似问题