php - feof error
- by TwixxyKit
The file that I'm trying to read is a pgp-encrypted file. This is part of the process to decrypt it and I'm actually attempting to read the contents into a string so that I can then decrypt it . I'm not sure if that's the core problem here or not, but I'm getting an error:
Warning: feof(): supplied argument is not a valid stream resource
Here's the file code:
if($handle = opendir($dir)) {
while( false !== ($file = readdir($handle))) {
if($file != "." && $file != "..") {
$fhandle = fopen($file, "r");
$encrypted = '';
$filename = explode('.',$file);
while(!feof($fhandle)) {
$encrypted .= fread($fhandle, filesize($file));
}
fclose($fhandle);
$decrypted = $filename[0].'.txt';
shell_exec("echo $passphrase | $gpg --passphrase-fd 0 -o $decrypted -d $encrypted");
}
}
}