Martin,
There are a bunch of post on phpbuilder about PGP encryption, but I don't think many address your question.
Here's some code I put together when I was working with the same issue. I could get 3 different methods to work. They are in the code below. The method you describe of writing clear_text to a temporary file is method 3 below and is well described by Julie Meloni at www.ThickBook.com (look in the tutorials area). Method 2 uses pipes. Method 1 uses process open (popen).
It's been quite a while since I looked at this stuff. You'll have to play with some of the pgp flags to get things working exactly right.
Hope it helps.
Rob
putenv("PGPPATH=/path/to/.pgp");
echo date("Y-m-d h:i:s")."<br>start<br>";
$msg = date("Y-m-d h:i:s",time()+36060)."\n"."Test data to encrypt";
echo "original: <br>".$msg."<br><br>";
// UNCOMMENT ONE OF THE THREE BLOCKS BELOW
//0x7552A4F7 is the KeyID
/ 1
$pp = popen("/usr/local/bin/pgpe -r 0x7552A4F7 -o /path/to/pgp_enc.txt", w);
fwrite($pp, $msg);
pclose($pp);
/
/ 2
$command = "echo '$msg' | /usr/local/bin/pgpe -r 0x7552A4F7 -o /path/to/pgp_enc.txt";
$result = exec($command, $msg_crypted, $errorcode);
/
/ 3
$fp = fopen("/path/to/pgp_plain.txt", "w+");
fputs($fp, $msg);
fclose($fp);
system("/usr/local/bin/pgpe -r 0x7552A4F7 -o /path/to/pgp_enc.txt -a /path/to/pgp_plain.txt");
unlink("/path/to/pgp_plain.txt");
/
// retrieve and display the data
$fp = fopen("/path/to/pgp_enc.txt", r);
$msg_crypted = fread($fp, filesize("/path/to/pgp_enc.txt"));
fclose($fp);
echo "<br>crypted: <br>".$msg_crypted."<br><br>";
unlink("/path/to/pgp_enc.txt");
mail("someone@somewhere","pgp test",$msg_crypted);
// Print confirmation to screen.
echo "
<H1 align=center>Thank You, $sender_name</h1>
<p align=center>Your secret message has been sent.</p>
";