我使用Ubuntu作为我的操作系统,并且我有XAMPP。在htdocs
文件夹中,我创建了一个项目文件夹,其中有index.php
文件。现在的index.php,代码的一部分,做到这一点:在Ubuntu中运行PHP程序 - fopen(“filename”,“w”):无法打开流:权限被拒绝
fopen("colors_new.csv", "w");
从manual,
'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
但该文件,而不是被创建的,我越来越
Warning: fopen(colors_new.csv): failed to open stream: Permission denied...
而当我查看项目文件夹时,colors_new.csv
文件未创建。
当我在运行Windows操作系统的另一台计算机上运行此程序时,它运行成功。该文件已成功创建。
如何解决Ubuntu中的这个问题?
我的尝试:
我试图运行sudo chmod 777 colors_new.csv
,但我得到chmod: can not access colors_new.csv. No such file or directory.
。我试着用文件名(如图所示)在项目目录中的WAS终端上执行此操作;以及提供文件的完整绝对路径。两次都有同样的错误。
注:我所看到的其他问题,如上面所指出的,我想给权限的文件。其他问题没有解决问题,下面接受的答案确实解决了这个问题。
在运行chmod命令之前,您必须在文件的位置。否则它会抛出错误:chmod:无法访问colors_new.csv。没有这样的文件或目录 –
这个问题不在文件中,因为它没有被创建,但是使用文件夹/目录,你很可能没有在目录/文件夹中创建文件的权限 – Epodax
可能有[无法打开流:没有这样的文件或目录](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) –