overwriting the existing file using file write action - coldfusion

I am facing a little problem
I am writing .html file from dynamic pages like
<cffile action="write" file="#filename#" output="#trim(content)#" />
but problem is that if file already exists, the file will not be overwritten but the last modified date and time are updated some how.
I have also tried to delete the file first if file already exists, but .html show still the old contents. But if I manually delete the file then the newly generated file has actual contents.

Related

How to get path of opened file in c++

I am trying to implement a file save function for my notepad project.
The file save function should be implemented like this :
Click Save Menu
If the texts were written on notepad never saved, print file dialog and set file path and then save.
If the texts already saved(may be modified), just save.
I think the path of the current text file is required for checking whether never or already saved.
(If the file never saved, the path doesn't exist.)
Then, How to get the path of the current file?
I am working with VS2019, MFC.
Thanks for your help.
Assume you use the document view architecture, you have a CDocument method that tell you the path of your files or, NULL/empty if the file is not saved yet: https://learn.microsoft.com/en-us/cpp/mfc/reference/cdocument-class?view=vs-2019#getpathname
"The document's fully qualified path. This string is empty if the document has not been saved or does not have a disk file associated with it."

ColdFusion 9 and Dropzone.js - send form elements on remove link

I have multiple dropzones in my ColdFusion code as such:
<cfform name='UploadFiles' action="uploadfiles.cfm" class="dropzone">
<input type="hidden" name="doctype" value="<cfoutput>#REQUIREMENT_CODE_KEY#</cfoutput>">
</cfform>
Currently when a file is uploaded, I put the original filename into my database and also rename the file and put that into the database. When the document is renamed, it uses the hidden value passed from the form (doctype).
Lets say someone uploaded the same file twice. This would put in the database two different renamed filenames (filename in image below), but it would have the same original filenames (orig_filename in image below). The only difference between the two records would be the value of the hidden element sent with the upload (doctype). ie:
The issue is that if they were to try to remove one of the files, both would be removed, because the only information dropzone has is the original filename. How can I get ColdFusion to pass the new filename back to the dropzone.js so that it can use that value to know exactly which line to delete?

How can I confirm a cffile write is successful?

I am using cffile to create a new file or update an existing file, depending on what the user requested. The request comes through a form from the previous procedure, so the code involving cffile looks like this:
<cfset thefile = "#form.dyn#">
<cfoutput>
<cfsavecontent variable = "testvar">
#form.editor1#
</cfsavecontent>
<cffile action = "write"
file = "/var/www/reports/#thefile#.cfm"
output = "#testvar#">
</cfoutput>
When I am done writing to the file, I want to confirm to the user that this happened. For a new file I could use IsDefined to check that it is there. But I can't think of a way to check for an existing file that was updated. I considered a try/catch on the cffile, but the catch operates only if nothing seems to go wrong. If I don't get an error on the catch, can I assume everything is all right? I would prefer a direct check if possible. Does anyone have an idea?
If <cffile> doesn't work, it'll tell you by throwing an exception. If it doesn't do that, you can safely assume it has worked. Don't over-engineer your app.
You could use cfdirectory with the action="list" and filter="your-filename" to get the following information about the uploaded file:
If action = "list", cfdirectory returns the following result columns, which you can reference in a cfoutput tag:
name: Directory entry name. The entries "." and ".." are not returned.
directory: Directory that contains the entry.
size: Directory entry size.
type: File type: file, for a file; dir, for a directory.
dateLastModified: The date that an entry was last modified.
attributes: File attributes, if applicable.
mode: Empty column; retained for backward compatibility with ColdFusion 5 applications on UNIX.
Of interest to you is the dateLastModified column.
So you should be able to do something like:
<cfdirectory action="list" name="dirQuery" directory="C:/var/www/reports/" filter="#thefile#.cfm">
Then you can dump that result to see what information is available to you:
<cfdump var="#dirQuery#">
The dateLastModified column can be accessed like:
<cfoutput>#dirQuery.dateLastModified#</cfoutput>
Use CFDirectory to get the file's dateLastModified before you update the file and then again afterwards. If they are not the same, then it was updated.

<cffileupload> and Database Insert of File Name

I am having a problem with the cffileupload tag and then inserting the names of the files uploaded into the database. It seems like there are no hooks back from the CF Action page that would say if it was successful, if the file was renamed, what the new filename is, and
Basically, I want a user to be able to upload mulitple files (up to 10) without a timeout and storing the name of the files in the database.
Any suggestions would be welcome! I've dug around on the interweb, and there doesn't seem to be any elegant solutions.
After the file is processed by <cffile action="upload">, there's a huge amount of information available via the variable specified in "result". This includes the original filename, the file size, and an indicator of success. Adobe's docs on cffile has the details. Your best bet is to create a temporary file, push the upload to there via cffile, evaluate success or failure, then push it into the database. Something like:
<cfset TemporaryFile = GetTempFile(GetTempDirectory(), "myAppTemp") />
<cffile action="upload" destination="#TemporaryFile#"
fileField="filefield" result="FileResults" />
Then you can access your file via the TemporaryFile variable, and the filename via FileResults.clientFile. FileResults.fileWasSaved should indicate success or failure of the upload and subsequent save to disk.

Is there a way to make cffile.oldFileSize return a correct value?

When working with cffile in ColdFusion, after an upload of a file to a webserver, the cffile structure is created that is supposed to have a value in it called "oldFileSize". Every time I do an upload and examine that value, it has the new file's size, not the overwritten file's size. Is there some setting somewhere to correct that or is this a bug in cffile in cf8?
Clarification: If you use the cffile command to upload a file to a server, it will attempt to store that file in the location you tell it in the command. If the destination already has a file there with the same name and path, then one of the options in your cffile command can bet to overwrite any existing file. If you do that, a structure is returned called cffile with an attribute called "oldFileSize". The documentation states that oldFileSize should be the size of the file that was overwritten. Instead, it's returning the size of the file being uploaded.
If the oldfilesize attribute is not returning correctly, I would use nameconflict=unique to preserve the old file. Then, you can use cfdirectory to check the old filesize, and cffile action="delete" and action="rename" to replace the old file, so that you have essentially overwritten the old file, only manually.
A bit of work, but if you need the information....
Ben Doom is correct about the work-around to the problem, but if you're not seeing the documented behavior, that's a bug and you should report it! Currently, there is no public bug tracker you can submit to (although there is a push for one and we should probably see it soon-ish), so the defacto standard is to post it as a comment on the documentation page.
Adobe staff does read and respond to comments and they will likely either respond that it will be fixed, or acknowledge that it is a bug but indicate there is no plan to fix it at this time. Either way, the responsible thing to do is to report the bug.
What overwritten file? It seems you are talking about two files when you only refer to one.