homepage Welcome to WebmasterWorld Guest from 54.166.8.138
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
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.
otem




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

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.

 

jatar_k




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

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

otem




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

Thanks for the reply.

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

Thanks

jatar_k




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

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.

otem




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

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.

jatar_k




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

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?

otem




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

Ah-ha!

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

jatar_k




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

nice work otem

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved