Closed Thread Icon

Preserved Topic: Creating a text file and forcing download on the fly? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21036" title="Pages that link to Preserved Topic: Creating a text file and forcing download on the fly? (Page 1 of 1)" rel="nofollow" >Preserved Topic: Creating a text file and forcing download on the fly? <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-12-2002 06:50

I'd like to start doing auto-.vcf creation. I'd like a user to be able to click on a link, such as /createVCF.php?id=666 and from that, the createVCF.php will do the following:

Query database and grab info for ID 666 (no big deal here)
Take that info and format a variable with it (no big deal here, either)
With that variable, create a text file with a .vcf extension, and prompt the SAVE AS dialog box so that the use can download the .vcf file.

Based on http://www.phpbuilder.com/mail/php-general/2001032/0505.php I *kinda* understand what's going on, but I'm a little stuck on the sending-it-to-the-browser-and-prompt-user part.

Anyone got some good links?

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-12-2002 07:18

Got it -

<?php
header("Content-Description: vCard for Pugzly - Pat Richard.vcf");
header("Content-Type: text/x-vcard;\n");
header("Content-Disposition: attachment; filename=\"Pat Richard.vcf\"");
header("Content-Transfer-Encoding: 7bit");
?>
BEGIN:VCARD
VERSION:2.1
N:Richard;Pat
FN:Pat Richard
NICKNAME:Pugzly
ORG:RunningWolf Corporation
TITLE:Sr. Designer
TEL;WORK;VOICE 586) 465-3482
ADR;WORK:;;38617 Wellington Dr.;C*****n Twp.;MI;48036-3526;United States of America
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:38617 Wellington Dr.=0D=0AC*****n Twp., MI 48036-3526=0D=0AUnited States of =
America
ADR;HOME:;;;;;;US
LABEL;HOME:US
URL;WORK:http://www.runningwolf.com
BDAY:19660527
EMAIL;PREF;INTERNET at@runningwolf.com
REV:20020712T054107Z
END:VCARD


Working example: http://development.runningwolf.com/code/php/auto_vcf/

This pulls static data, but the dynamic data is just the same...



[This message has been edited by Pugzly (edited 07-12-2002).]

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 07-12-2002 11:31

Now that was sweet!
Got the download, saved it, opened it straight into outlooks contacts & saved it, everything in the right place
/Dan


{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-17-2002 00:47

So, say I want to do the same thing with a text file with information from a database.

Would it look like

code:
<?php
header("Content-Description: Text File - TextFile.txt");
header("Content-Type: text/plain;\n");
header("Content-Disposition: attachment; filename=\"TextFile.txt\"");
header("Content-Transfer-Encoding: 7bit");

/**
* Function to Dump the mySQL data into a String
**/

echo(textFileDump());
?>



Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-17-2002 04:15

Yes. That's what I've been doing. I pass a variable ("$ID") to the page. The page grabs data from MySQL for that ID, then prints it after the headers.

So I end up with a link "Add this Contact to Outlook" that, when clicked, pushes the dynamically created vCard.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-17-2002 06:35

So, I have been looking at this. Why the 7 bit Encoding? That is the one thing I don't understand.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-17-2002 07:30

Actually, 8bit works as well. Can't recall why I was using 7bit.

Anyways, here is an updated version that addresses a known issue with headers and IE 5.5 SP1:

<?php
header("Content-Description: vCard for Pugzly - Pat Richard.vcf");
header("Content-Type: text/x-vcard;\n");
if(strstr($HTTP_USER_AGENT, 'MSIE 5.5')) { // spell 'attachment' wrong for msie5.5 sp1, cause microsoft is retarded
header("Content-Disposition: atttachment; filename=\"Pat Richard.vcf\"");
} else {
header("Content-Disposition: attachment; filename=\"Pat Richard.vcf\"");
}
header("Content-Transfer-Encoding: 8bit");
?>
BEGIN:VCARD
VERSION:2.1
N:Richard;Pat
FN:Pat Richard
NICKNAME:Pugzly
ORG:RunningWolf Corporation
TITLE:Sr. Designer
TEL;WORK;VOICE 586) 465-3482
ADR;WORK:;;38617 Wellington Dr.;C*****n Twp.;MI;48036-3526;United States of America
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:38617 Wellington Dr.=0D=0AC*****n Twp., MI 48036-3526=0D=0AUnited States of =
America
ADR;HOME:;;;;;;US
LABEL;HOME:US
URL;WORK:http://www.runningwolf.com
BDAY:19660527
EMAIL;PREF;INTERNET at@runningwolf.com
REV:20020712T054107Z
END:VCARD


I hope this one makes sense!



[This message has been edited by Pugzly (edited 07-17-2002).]

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-22-2002 17:00

Okay, a little snag in the plan here....


If I call something like printvcf.php, the headers work fine.

But if I call something like printvcf.php?uid=1, the headers don't work, and the data prints to the screen. This happens even if I hard code the UID in the select statement. As soon as there are paramaters and values in the URL, it stops working.

Does anyone know how to get around this?

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-22-2002 17:03

Hmm....for some reason it just started working...

"I didn't touch nuttin! I swear!"

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-23-2002 00:21

Weird isn't it...

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-23-2002 00:25

I'll say!

I didn't know that some email clients that support vCards support images and other files within those vCards. Cool!

Next stop - vCalendar!

« BackwardsOnwards »

Show Forum Drop Down Menu