Solved

Deleting a file from the coldfusion server

Posted on 2008-10-16
6
152 Views
Last Modified: 2013-12-16
How do I delete a file directly after it has been selected for download?  Everything I keep doing ends up deleting the entire directory or just a specific file.  

I'm sorry if this is a stupid question.
0
Comment
Question by:dthomas06
  • 3
  • 2
6 Comments
 
LVL 36

Expert Comment

by:SidFishes
ID: 22732912
can you post a code snip?
0
 

Author Comment

by:dthomas06
ID: 22732986
<cfloop query="getfile">
   <cfif Type IS "Dir">
     <a href="#cgi.SCRIPT_NAME#?DirPath=#url.DirPath#\#name#&CaseN=#url.CaseN#"><img src="../images/folder.gif" width="19" height="17" border="0"> #name#</a>
     <cfelse>
    #name#<a href="NewIndex3_VOpenFile.cfm?filepath=#url.DirPath#%5C#name#" target="_blank"> Download</a> <cffile action="delete" file="#url.DirPath#%5C#name#">
</cfif>         
  <br>
</cfloop>
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 22732990
it is not a stupid question, just a very unclear one:
- what do you mean by "after is has been selected for download"? when exactly is this moment? where in your application logic does this happen?
- post the code you are currently using to delete the file, and it will be easier for everyone to see where the problem may be.

"Everything I keep doing ends up deleting the entire directory..." - not good
"... or just a specific file." - sn;t this what you want, to delete a specific file?
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:dthomas06
ID: 22733321
Sorry it's not clear.  

After the people log in to the system and click to see what files are available for download a list is pulled of Files located on a section of our directory.  As soon as they click download on a specific file or several minutes after the fact they want the file to be deleted from the directory.  

As far as the specific file being deleted the only way that happens is when I plug in the files name in the tag <cffile action="delete" file="#url.DirPath#%5C#name#">.  

0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 100 total points
ID: 22733590
thanks, it is much clearer now.

an obvious problem for you here is that you have no idea if the file has finished downloading or not. a slow connection, network congestion and a bunch of other factors can play a role in download speed. this gets more important with file size increase.

so, a couple of ways to proceed here. both ways will require an intermediary page, so your links for downloading should not link directly to the files, but to this intermediary page, passing a reference to the file to be downloaded to it in some way (url var, session var, etc). the function of this intermediary page will depend on the way you choose to serve up your files for downloading:

a) you can, through a combination of cfheader and cfcontent tags, 'stream' the file to your user, which will prompt him/her to save the file to their computer. the cfcontent tag has a deleteFile attribute which, hen set to "yes" deletes the file from the server after sending it to the user's browser.
an example of this would be:
<cfheader name="Content-Type" value="application/pdf">
<cfheader name="Content-Disposition" value="attachment; filename=mypdf.pdf">
<cfcontent type="application/pdf" file="C:\pdfs\mypdf.pdf" deletefile="Yes">

the above, or something similar, would be the content of the intermediary page in this case.

b) another option is to store the info about which files have been selected for downloading and when somewhere (db, application scope, a text file, etc), and then configure and run a schedule task that will delete all the files that have been recorded X time units ago, i.e. run a task every 30 minutes that deletes all files that have been stored as selected for download more than 10 minutes ago (assuming 10 minutes is enough to download your largest file over the slowest connection).

in this case the intermediary page will record the requested file and the time of request and then can just cflocation to the actual file.

hth
0
 

Author Comment

by:dthomas06
ID: 22733835
Thank you so much azadisaryev.  I just did it and it worked.  I was concerned about a file downloading quick enough and said numerous times that we needed to make sure the file would complete downloading as we are looking at files over 40 MB.  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now