简体   繁体   English

无法将文件写入AWS EC2实例-PHP

[英]Cannot write a file to AWS EC2 instance - PHP

I am trying to create and write a file to ec2 instance. 我正在尝试创建文件并将其写入ec2实例。 I am getting the error below despite the folder that i am writing possessing all the permissions required. 尽管我正在编写的文件夹拥有所需的所有权限,但我仍收到以下错误。

 $handle = fopen("thumbnailFolder/testFile.txt", "r");  // line 4

 if($handle != false){
    echo 'File created!';
 }else{
    echo 'File create failed!';
 }

The 'thumbnailFolder' has the following permissions: “ thumbnailFolder”具有以下权限:

 drwxrwxrwx

Error message: 错误信息:

 fopen(thumbnailFolder/testFile.txt): failed to open stream: No such file or directory in /var/www/html/book_aws/my_server/folder/web/thumbnailTest.php on line 4

File create failed! 文件创建失败!

As the error clearly say. 正如错误明确指出的那样。 System is failing to open the file which is not there. 系统无法打开不存在的文件。

$handle = fopen("thumbnailFolder/testFile.txt", "r");

Above code open files in read mode. 上面的代码以读取模式打开文件。 if there is no files then throws an error. 如果没有文件,则抛出错误。

If you want to open file to write then use try below code, this tries to open file and sets pointer at the begining if file is not there then creates the file in given name. 如果要打开文件进行写入,请使用以下代码尝试,这将尝试打开文件,并在文件不存在的地方将指针设置在开头,然后以给定名称创建文件。 for read and write use w+ instead of w 对于读写,请使用w +而不是w

$handle = fopen("thumbnailFolder/testFile.txt", "w");

There are different modes with respect files. 尊重文件有不同的模式。 you can check below link for further details. 您可以在下面的链接中查看更多详细信息。

http://php.net/manual/en/function.fopen.php http://php.net/manual/en/function.fopen.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM