Solved

Deleting a file from the coldfusion server

Posted on 2008-10-16
6
158 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
New Website 15 33
Drawing a Polygon with Google Maps 3 430
Spell check for online editor 7 80
How to protect website documents without Windows Security 7 118
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 …
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

733 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