Skip to main content
BreakawayPaul
Inspiring
April 7, 2016
Question

Delete files after cfzip?

  • April 7, 2016
  • 1 reply
  • 772 views

I've got a web app that allows users to save database results as a PDF file (I use cfdocument for this).  There's also an option for them to select up to 20 records to PDF and zip (I use cfzip for this) but with almost 6000 records in the database, I don't want PDFs to pile up. It's easy to make the script delete the zipfile after download, but I'm trying to figure out a way to clean up the PDFs.

One idea was to stick a unique identifier in the PDF filenames, then delete everything with a wildcard, but is there a better way?

This topic has been closed for replies.

1 reply

WolfShade
Legend
April 7, 2016

Instead of saving PDF files to the server and zipping them, what I would do is:

If it's only one record (ergo, one PDF), I'd create the binary and use CFHEADER and CFCONTENT to stream it to the browser; that way you won't have to save it to the server HD -OR- worry about deleting it, afterwards.

If there will be multiple PDFs (ergo, up to 20 records selected), I'd create the binaries in a loop, saving each to a different variable, then do a readbinary() in another loop, using CFZIP to create the ZIP file and email it (again, not saving to server HD), using CFMAILPARAM to attach the ZIP to the email.

HTH,

^_^

BreakawayPaul
Inspiring
April 7, 2016

Yeah, that's exactly what I do with single records, and it works great.  But with multiple records, I end up with leftover PDFs.

I'll have to research that readbinary() thing.  I've never used that before, so I wouldn't know where to start!