(Linux)
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 .

<?php

$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");

?>
  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.

the www-data thing worked. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.