Solved

Deleting a file from the coldfusion server

Posted on 2008-10-16
6
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…

717 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