#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    15
    Rep 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??
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,332
    Rep Power
    594
    Rather than try to read the mail manually and putting it into a variable, can you use the PHP imap functions?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    15
    Rep Power
    0

    I would if I could


    Originally Posted by gw1500se
    Rather than try to read the mail manually and putting it into a variable, can you use the PHP imap functions?
    Unfortunately I don't have access to the imap functions, which is why I ended up with the attachments in variables.

    Thanks,
    Tom
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,332
    Rep Power
    594
    Maybe this this will help.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo