
January 8th, 2013, 12:12 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 13
Time spent in forums: 1 h 33 m 37 sec
Reputation Power: 0
|
|
|
How to read pdf/doc/excel data from a php variable
Is there a way to read a pdf/doc/excel data where the data resides in a variable? The data in question comes from email attachments I have been able to open, which is separate from the email content. I also have the content type, which tells me if the attachment is a pdf, doc file, excel etc.
I put the attachment content(data) into an array variable with the content type and the original file name of the email that the data was attached to. The question is, is there a way to read the pdf/doc/excel files directly from the php variable? The best I have been able to do is to create a file, load the file with the variable(data) and then open the file. This works fine except now I'm stuck with a new file, which I don't need. I tried to unlink the file after the read, but the file does not get deleted.
Thanks,
Tom
//Table array 0= filename, 1 = data, 2 = content type
$TableArray = $_POST['TableArray'];
$i = $_POST['submit']; // tells me which attachment to read
$ContentType = "Content-Type: " . $TableArray[$i][2];
header($ContentType);
$save_dir = "/tmp/";
if ($fp = fopen($save_dir.$TableArray[$i][0], 'w'))
{
fwrite($fp,$TableArray[$i][1]); // load the file with data
fclose($fp);
}
readfile($TableArray[$i][0]); // read and display the file
unlink($TableArray[$i][0]); // file is still present??
|