Solved

Deleting a file from the coldfusion server

Posted on 2008-10-16
6
146 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Drawing a Polygon with Google Maps 3 297
About Wordpress website 3 92
What xml editor to use. 8 78
graphic software 6 81
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 reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

747 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

14 Experts available now in Live!

Get 1:1 Help Now