Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Question about cffile

Guest
Feb 01, 2011 Feb 01, 2011

Him I am using the following cffile to upload an image to a folder on the website, but wanted to know if there a way that it will rename the file according to the userID in the database. For example.... image name is jackson.jpg and Jackson's userID is 12, so i would like the image to be renamed to 12.jpg. Hope thats makes sense. I know this is a super simple upload system which is why i need help. Thanks

======= cffile code =============

<cfif isDefined("fileUpload")>
  <cffile action="upload"
           fileField="fileUpload"
           destination="C:\ColdFusion9\wwwroot\myWebsite\user_images"
          accept="image/jpg,image/jpeg">
     <p>Thank you, your file has been uploaded.</p>
</cfif>
<cfform enctype="multipart/form-data" method="post">
  <cfinput type="file" name="fileUpload" />
  <cfinput type="submit" name="file_submit" value="Upload File" />
</cfform>

1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Feb 03, 2011 Feb 03, 2011

Can't figure out why it works in FF, but not IE.

| h1. The MIME type of the uploaded file image/pjpeg

Only files of type image/JPG,image/JPEG can be uploaded.

The reason is right there in the error message 😉 "image/Pjpeg" is not in the list of mime types you are accepting. Internet Explorer often has its own ideas about mime types.

That said, do not rely on the "accept" attribute. Mime types are easy to exploit:

Message was edited by: -==cfSearching==-

Translate
Contributor ,
Feb 01, 2011 Feb 01, 2011

After you upload thefile, you can rename it by using this in Coldfusion using the action = rename of CFFILE..

or

I hope you can do that in Javascript also, while uploading you will be calling some function
to check whether its an acceptable format, in that function you could call the rename function.

cffile action = "rename"

<!--- Source Document is read-only but when renamed it becomes normal (not hidden or  
    read-only). --->
<cffile action = "rename" source = "c:\files\memo\readonlymemo.doc" 
    destination = "c:\files\memo\normalmemo.doc" attributes="normal">





Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 02, 2011 Feb 02, 2011

Thanks for your post. How would i link the two?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 02, 2011 Feb 02, 2011

No linking..

Its the two options you could pick anyone which is simple.

Try it and let me know.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 03, 2011 Feb 03, 2011

Korrupt, try this:

<cfif isDefined("fileUpload")>
  <cffile action="upload"

          fileField="fileUpload"
          destination="C:\ColdFusion9\wwwroot\myWebsite\user_images"
          accept="image/jpg,image/jpeg" />

  <cffile action="rename"

          source=cffile.serverDirectory & cffile.serverFile

          destination=cffile.serverDirectory & {newFileName} & cffile.serverFileExt />


  <p>Thank you, your file has been uploaded.</p>
</cfif>


<cfform enctype="multipart/form-data" method="post">
  <cfinput type="file" name="fileUpload" />
  <cfinput type="submit" name="file_submit" value="Upload File" />
</cfform>

Replace {newFileName} with the variable holding the string of whatever you want the file name to be.

Just a heads up about about the cffile scope: when you use the cffile tag to upload a file to the server, the cffile scope is populated with data about the upload attempt.  You can also specify a variable name to be filled with the data in the result attribute if you prefer. See the LiveDocs page on cffile action="upload".

Message was edited by: G. Taylor

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 03, 2011 Feb 03, 2011

Thanks for the posts. I got it to work in FF just fine and the way i want it to, but in IE i get this error and i don't know why.

Can't figure out why it works in FF, but not IE.

---------- Error message -----------

The MIME type of the uploaded file image/pjpeg was not accepted by the server.


Only files of type image/jpg,image/jpeg can be uploaded.
Verify that you are uploading a file  of the appropriate type.
The  error occurred in  C:\ColdFusion9\wwwroot\poll_system\admin_section\picture_upload.cfm: line 23
21 :             fileField="fileUpload"
22 :             destination="C:\ColdFusion9\wwwroot\Client\Client_images"
23 :           accept="image/jpg,image/jpeg">
24 :     <font size="+1">The file has been uploaded.</font><br />
25 :     Don't forget to add the image name to the "Politician Image" field.<br />
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 03, 2011 Feb 03, 2011

Can't figure out why it works in FF, but not IE.

| h1. The MIME type of the uploaded file image/pjpeg

Only files of type image/JPG,image/JPEG can be uploaded.

The reason is right there in the error message 😉 "image/Pjpeg" is not in the list of mime types you are accepting. Internet Explorer often has its own ideas about mime types.

That said, do not rely on the "accept" attribute. Mime types are easy to exploit:

Message was edited by: -==cfSearching==-

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 04, 2011 Feb 04, 2011

Thank you that fixed it.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2011 Feb 04, 2011

accept="image/*"

can be quite handy as default for image files.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 04, 2011 Feb 04, 2011
LATEST

Yes, but not very safe.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources