I have a question about this script which encrypts a text file on the server.
Is there any way to make this script have a fail safe. If for some reason it does not delete the unecrypted file on the server can the script set a trigger to send an error and then remove the unencrypted file.
// Path to GNUPG
putenv("GNUPGHOME=/tmp/.gnupg");
// Create Temp Token
$tmpToken = md5(uniqid(rand()));
// encrypt data
$plainTxt = "/tmp/" . "$tmpToken" . "data";
$crypted = "/tmp/" . "$tmpToken" . "pgpdata";
// Write Text to Encrypt
$fp = fopen($plainTxt, "w+");
fputs($fp, $mail_body);
fclose($fp);
// Encrypt Data
system("/usr/bin/gpg --encrypt -ao $crypted -r 'KEY IS HERE' $plainTxt");
// Get the encrypted data
$fd = fopen($crypted, "r");
$mail_cont = fread($fd, filesize($crypted));
fclose($fd);
// Delete files
unlink($plainTxt);
unlink($crypted);
Any help would be greatly appreciated.