Solved

Coldfusion rename file and place in another directory

Posted on 2015-01-09
1
155 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

790 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