php - feof error

Posted by TwixxyKit on Stack Overflow See other posts from Stack Overflow or by TwixxyKit
Published on 2010-05-20T16:49:31Z Indexed on 2010/05/20 16:50 UTC
Read the original article Hit count: 281

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about feof