abhishek telang
abhishek telang

Reputation: 3

Cannot open and write contents to file on AWS EC2 in PHP Script

I am using this code to read the file and add new data at the end of file.

$fh = fopen($myFile, 'a') or die("can't open file");

The problem is that this code works fine on local server but giving an error of can't open file on Amazon EC2 server.

Also file i use the parameter r instead of a it works but i can't understand why isn't the a parameter working?

Upvotes: 0

Views: 1260

Answers (2)

René Höhle
René Höhle

Reputation: 27305

This happen if you don't have write permissions. So you can try to get the error. Remove your die and use the following command to get the error.

error_get_last() as example:

print_r(error_get_last());

This should give you the last error for fopen.

Upvotes: 1

sorak
sorak

Reputation: 2633

The r parameter is opening for reading. The a parameter is for append, so it may return an error if you do not have write access to the file in question.

Upvotes: 1

Related Questions