Solved

Coldfusion rename file and place in another directory

Posted on 2015-01-09
1
157 Views
Last Modified: 2015-01-10
I need the path name in order to rename a file. The user selects the file to be renamed and ColdFusion should rename the file.

My challenge is how to get the pathname of the selected file.


<!--- Check to see if the Form variable exists. --->
<cfif isDefined("Form.FileContents") >


<!---
<cffile
action = "rename"
    destination = "pathname"
    source = "full pathname"
    attributes = "file attributes list"
    mode = "mode"> --->a
<cfelse>
    <!--- If FALSE, show the Form. --->
    <form method="post" action=<cfoutput>#cgi.script_name#</cfoutput>
        name="uploadForm" enctype="multipart/form-data">
        <input name="FileContents" type="file">
        <br>
        <input name="submit" type="submit" value="Upload File">
    </form>
</cfif>
0
Comment
Question by:Errol Farro
1 Comment
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 40541651
(Not sure I follow what you're ultimately trying to do, but ...)

>> I need the path name in order to rename a file.

Which path are you referring to?

A) The original location of the file on the user's computer before they upload it, ie:
      C:\Users\Bob\PhotosFromCompanyRetreat.zip
 
-OR-

B) The path on the server after it's uploaded? ie:
     c:\yourApp\uploadedFiles\PhotosFromCompanyRetreat.zip

If you mean A) you can't.  Browsers are not allowed to send information about paths on the client machine due to security restrictions.  IIRC some versions of IE might, but that's a fluke.

If you mean B) - after the form is submitted use <cffile action="upload" ...> . You can specify whatever directory you want. The upload action will populate a structure named CFFILE. It'll contain details about the file, including it's location on the server. You can use these variables to obtain the final name and location of the file on the server:

          #CFFILE.serverFile#          <!--- file name and extension
          #CFFILE.serverDirectory#  <--- folder location

If that's not what you mean, can you provide more details? If you explain the overall objective (without code) we may be able to suggest other options.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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