In the following code all I'm trying to do is open a file but evertime I run this script the fopen function jumps right to the die() function. Any ideas? The file accounts.txt does exist in the same directory, and I also tried refrencing the file via ./accounts.txt .


$email = $_POST['email'];
$psswd = $_POST['psswd'];

echo "The email address is $email<br>";
echo "The password is $psswd<br>";

$file = fopen("accounts.txt", 'r+') or die("Failed to open file");

4 Years
Discussion Span
Last Post by lewashby
  1. Make sure the file is in the same directory.
  2. Make sure the file is called "accounts.txt"
  3. change r+ to r and see if that works.

Make sure you are actually hitting the file, in past experience I have found that giving the full path to the file with the use of $_SERVER['DOCUMENT_ROOT']; works.

The other thing to look at is does the web server and PHP actually have the appropriate permissions to access the file?
If it is running Apache then www-data needs permission (I don't know about other web server software, but the principals are the same).

Stick the following and see what the output is, ini_set('display_errors', 1) without the or die() This should give us some more information such as Permission Denied or that it cannot find the file.

Edited by Octet

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.