Welcome to WebmasterWorld Guest from 54.162.155.183

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Reading zipped files from attachments of emails stored as a text file

I would like to run a script that will read and process the incoming data.

     
3:11 pm on May 24, 2007 (gmt 0)

5+ Year Member



I have a report that is automatically emailed to me every morning, with the corresponding email account setup to save the incoming emails into a .txt file. This email report contains a zipped csv file that is attached.

What I would like to do is to create a php script that when initiated will open this .txt file, grab the attachment, unzip the attachment, read the contents, and add it into a database.

I know how to have script read a file, and then grab the text that I'm interested in, however, once I have this text, how would I go about unzipping it to read the resulting data.

By hand I've tried just taking the attached data, and pasting it into notepad and trying to save it as a .zip file, and then have tried to open it, but I get errors even when I try to do that. "The zipped file is invalid or corrupt".

Any help would be greatly appreciated. Thanks.

3:30 pm on May 24, 2007 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



we used to use shell scripts to do this but you can do the same using Program Execution Functions [php.net], or similar.

some of these are disabled on shared hosts

5:51 pm on May 24, 2007 (gmt 0)

5+ Year Member



Thanks for the reply.

From your reply, and I correct in thinking the file will need to be executed?

Thanks

5:56 pm on May 24, 2007 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I was thinking you could use exec, or another, to call gunzip on the file. Then you can continue with saving it to your db.

sorry I realize now I wasn't overly clear.

12:03 am on May 25, 2007 (gmt 0)

5+ Year Member



Thanks for your help.

Before I get to far into this, should I be concerned that when I try to grab the attachment code and save it as a zip file, that I can't open it?

Do files when they get attached to an email get encoded somehow, and do I need to decode this attachment before I can start unzipping it?

The email says above the attachment "Content-Transfer-Encoding: base64"

Thanks.

1:26 am on May 25, 2007 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



off the top of my head, I wouldn't think so. You should be able to manually unzip it and open it without problem.

I wonder about this

>> the corresponding email account setup to save the incoming emails into a .txt file

are you corrupting it on receipt?

1:01 am on May 26, 2007 (gmt 0)

5+ Year Member



Ah-ha!

Figured it out. I first needed to decode it using base64_decode($attachment);

12:37 pm on May 26, 2007 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



nice work otem
 

Featured Threads

Hot Threads This Week

Hot Threads This Month