RE: [PHP] Working with email piped to PHP

From: Date: Sun, 04 Feb 2001 11:33:21 +0000
Subject: RE: [PHP] Working with email piped to PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-38095@lists.php.net to get a copy of this message
> # This is the standard input script. > > $fp = fopen("php://stdin","r"); > $writer_file = fopen("test.txt","w"); > fwrite($writer_file,"$fp"); > fclose($writer_file); > fclose($fp); > > ?> > > As stated, it does create the test.txt in the specified location, > however, > upon inspection of the file, it only shows the following text: > "Resource id > #1" on the first line, and that's it. This is what would be expected, your writing a file pointer to file not the coentents of the stdin, you need to do somthing along the lines of the following // Untested Code /* -*- Open stdin for reading -*- */ $fp = fopen("php://stdin","r"); /* -*- Open test.txt for writing -*- */ $writer_file = fopen("test.txt","w"); /* -*- Check both were opened -*- */ if($fp && $writer_file) { /* -*- Read in stdin -*- */ while(!feof($fp)) { $stdin .= fread($fp, 4096); } /* -*- Write to test.txt -*- */ if (sizeof($stdin) != fwrite($writer_file, $stdin, sizeof($stdin))) { //Not all of stdin was written to file } else { /* -*- Close Files -*- */ fclose($writer_file); fclose($fp); } } else { //files were not opened } James

« previous php.general (#38095) next »