Whatever message this page gives is out now! Go check it out!
<head><title>Specify File to Upload</title></head>
<body>
<h2>Specify File to Upload</h2>
<!--- the action attribute is the name of the action page --->
<form action="uploadfileaction.cfm"
enctype="multipart/form-data"
method="post">
<p>Enter the complete path and filename of the file to upload:
<input type="file"
name="FiletoUpload"
size="45">
</p>
<input type="submit"
value="Upload">
</form>
</body>The form does not work until you write an action page for it (see the next procedure). |
Code | Description | |
| Create a form that contains file selection fields for upload by the user. The action attribute value specifies the ColdFusion template that processes the submitted form. The enctype attribute value tells the server that the form submission contains an uploaded file. The method attribute is set to post to submit a ColdFusion form. | |
| Allow the user to specify the file to upload. The file type instructs the browser to prepare to read and transmit a file from the user system to your server. It automatically includes a Browse button to let the user look for the file instead of manually entering the entire path and filename. |
<head> <title>Upload File</title> </head> <body> <h2>Upload File</h2> <cffile action="upload" destination="c:\temp\" nameConflict="overwrite" fileField="Form.FiletoUpload"> <cfoutput> You uploaded #cffile.ClientFileName#.#cffile.ClientFileExt# successfully to #cffile.ServerDirectory#. </cfoutput> </body> </html> |
destination="c:\temp\" |
Code | Description | |
| Output the name and location of the uploaded file on the client machine. | |
| Specify the destination of the file. | |
| If the file exists, overwrite it. | |
| Specify the name of the file to upload. Do not enclose the variable in number signs. | |
| Inform the user of the file that was uploaded and its destination. For information on scope variables, see Evaluating the results of a file upload below. |
fileField="Form.FiletoUpload" destination="c:\uploads\" nameConflict="Overwrite" accept="image/gif"> |
fileField="Form.FiletoUpload" destination="c:\uploads\" nameConflict="Overwrite" accept="image/gif, image/jpeg"> |
fileField="Form.FiletoUpload" destination="c:\uploads\" nameConflict="Overwrite" accept="image/*"> |
mode=444 |
mode=744 |
Variable | Description |
attemptedServerFile | Initial name that ColdFusion uses when attempting to save a file; for example, myfile.txt. (see Resolving conflicting filenames). |
clientDirectory | Directory on the client system from which the file was uploaded. |
clientFile | Full name of the source file on the client system with the filename extension; for example, myfile.txt. |
clientFileExt | Extension of the source file on the client system without a period; for example, txt (not .txt). |
clientFileName | Name of the source file on the client system without an extension; for example, myfile. |
contentType | MIME content type of the saved file; for example, image for image/gif. |
contentSubType | MIME content subtype of the saved file; for example, gif for image/gif. |
dateLastAccessed | Date that the uploaded file was last accessed. |
fileExisted | Indicates (Yes or No) whether the file existed with the same path. |
fileSize | Size of the uploaded file. |
fileWasAppended | Indicates (Yes or No) whether ColdFusion appended the uploaded file to an existing file. |
fileWasOverwritten | Indicates (Yes or No) whether ColdFusion overwrote a file. |
fileWasRenamed | Indicates (Yes or No) whether the uploaded file was renamed to avoid a name conflict. |
fileWasSaved | Indicates (Yes or No) whether ColdFusion saved the uploaded file. |
oldFileSize | Size of the file that was overwritten in the file upload operation. Empty if no file was overwritten. |
serverDirectory | Directory where the file was saved on the server. |
serverFile | Full name of the file saved on the server with the filename extension; for example, myfile.txt. |
serverFileExt | Extension of the file saved on the server without a period; for example, txt (not .txt). |
serverFileName | Name of the file saved on the server without an extension; for example, myfile. |
timeCreated | Date and time the uploaded file was created. |
timeLastModified | Date and time of the last modification to the uploaded file. |
Action | Example code | |
Move a file |
| |
Rename a file |
| |
Copy a file |
| |
Delete a file |
|
source="c:\files\upload\keymemo.doc" destination="c:\files\backup\" attributes="ReadOnly"> |
<head> <title>Read a Text File</title> </head> <body> Ready to read the file:<br> <cffile action="read" file="C:\inetpub\wwwroot\mine\message.txt" variable="Message"> <cfoutput> #Message# </cfoutput> </body> </html> |
<head> <title>Put Information into a Text File</title> </head> <body> <h2>Put Information into a Text File</h2> <form action="writetextfileaction.cfm" method="Post"> <p>Enter your name: <input type="text" name="Name" size="25"></p> <p>Enter the name of the file: <input type="text" name="FileName" size="25">.txt</p> <p>Enter your message: <textarea name="message"cols=45 rows=6></textarea> </p> <input type="submit" name="submit" value="Submit"> </form> </body> </html> |
<head> <title>Write a Text File</title> </head> <body> <cffile action="write" file="C:\inetpub\wwwroot\mine\#Form.FileName#.txt" output="Created By: #Form.Name# #Form.Message# "> </body> </html> |
<head> <title>Append a Text File</title> </head> <body> <cffile action="append" file="C:\inetpub\wwwroot\mine\message.txt" output="Appended By: #Form.Name#"> </body> </html> |