Thread: Create and Kill temporary files?
Results 1 to 3 of 3
Help Me Kill This Stupid Url Box!! It's Driving Me Insane! Forum: Myspace ForumReplies: 6
Starting a new website. Mysql wants to kill me. Forum: PHP ForumReplies: 4
Warning - Spyware Programs that KILL affiliate cookies Forum: Affiliate Marketing and Reseller ProgramsReplies: 6
09-08-2004, 10:57 AM #1
Create and Kill temporary files?
Okay, this is a followup to the post on Creating PDFs Dynamically. I've figured out the nitty gritty details of creating the PDFs and shooting them to the user; however, as I want to maintain a nice, clean web server and don't want to schedule tasks to clean out these PDFs... how can I redirect them to the PDF, but delete the file?
Here's the code I have:
<% @Language="VBScript" %> <% Response.Buffer = True %> <% Set theDoc = Server.CreateObject("ABCpdf4.Doc") theDoc.Rect.Inset 20, 20 theURL = Request.ServerVariables("HTTP_REFERER") & "&medium=printer" response.Write(theURL) theID = theDoc.AddImageUrl(theURL, True, 0, False) Do theDoc.FrameRect If theDoc.GetInfo(theID, "Truncated") <> "1" Then Exit Do theDoc.Page = theDoc.AddPage() theID = theDoc.AddImageToChain(theID) Loop For i = 1 To theDoc.PageCount theDoc.PageNumber = i theDoc.Flatten Next filepath = "c:\inetpub\wwwroot\customers\cer\pdfs\" relativepath = "pdfs/" filename = Replace(CStr(CDbl(Now)) & CStr(Timer), ".", "") & ".pdf" theDoc.Save filepath & filename response.addheader "content-disposition","attachment; filename='" & Filename & "'" response.Redirect(relativepath & filename) Set objFSO = Server.CreateObject("Scripting.FileSystemObject") objFSO.DeleteFile(filepath & filename)
This "works"; I just can't delete the file because... it's already redirected. I considered a popup window... but ewww...
09-08-2004, 07:13 PM #2
Would it make more sense to create the PDF dynamically in an ASP script, then write directly to the browser? You can set a content-type of application/pdf, then write to standard output instead of to a file.
However..I can't remember if you can actually do this with abcPDF.
Other than that, you could check for an existing file on page load, and delete that one first before creating the new one. As long as its older than 5 minutes, say.If one of our members helps you, please click the icon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
09-09-2004, 11:15 AM #3
The page I posted actually is a createpdf.asp (real original, huh?). The main page's menu points to this ASP page (hence the URL = HTTP_REFERRER), reforms it based on a specific style sheet (the &medium=printer), and proceeds to generate the PDF. The PDF generation works flawlessly (I danced). I guess I'm not sure how to directly write to the screen--if I even can. I'll check that options for saving I have besides .Save--a quick glance while typing hasn't turned up anything that might work.