|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Renaming an Uploaded File and Adding to Database
I have a form where a user can upload a pdf file and it gets uploaded to a specified destination. However once this is uploaded, how can I change that filename on the fly and then input the reference destination into a field in my database? I hope this question is clear. Thanks.
|
|
#2
|
|||
|
|||
|
You can rename the file using CFFILE, and then update the database however you need to.
http://livedocs.macromedia.com/cold...4.htm#wp1098668
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
I understand what you are saying. However, is there a way to upload and rename using one cffile instead of doing a cffile for an upload and then a cffile for a rename. I say this because I do not know what the source would be when they upload it since they can upload whatever and wherever file they choose. I would want to dynamically get that file name and then change it to what I want. Does this make sense?
|
|
#4
|
|||
|
|||
|
Yes, you can do this in one CFFILE like this:
<cffile action="upload" destination="/path/to/some/directory/#createUUID()#.gif" ... /> Obviously, replace the createUUID() function with whatever you want the name to be. |
|
#5
|
|||
|
|||
|
Thank you, that actually helps a lot. My main problem now is, when I try to specify the destination as a certain field in the database, it does not work. Example:
<cffile action="upload" accept="application/pdf" filefield="Uploading" destination="mypath\#Form.MaterialId#.pdf" nameconflict="overwrite"> #Form.MaterialId# is not getting evaluated and it just places the pdf as this ".pdf" Do you know why this is not working? |
|
#6
|
|||
|
|||
|
Can you dump out form.materialID and then do a cfabort right before the cffile tag? Is it defined?
|
|
#7
|
|||
|
|||
|
Actually that value was null so it was correct in returning nothing. However I have this code now and it is still not working. The code is as follows.
<cfquery name="getMaterialId" datasource="****" > SELECT MaterialId FROM materialView WHERE material = '#Form.Material#' AND mfg = '#Form.Mfg#' </cfquery> <cfoutput> <cfif isDefined("Form.Upload")> <cffile action="upload" accept="application/pdf" filefield="Uploading" destination="myPath\#getMaterialId.MaterialId#.pdf" nameconflict="overwrite"> </cfif> </cfoutput> |
|
#8
|
|||
|
|||
|
What is the error?
Is the file being named ".pdf" still? If so, it's possible that getMaterials.MaterialID is not defined (i.e., the query returned no records). Try outputting the variable first: <cfquery name="getMaterialId" ...> SELECT.... </cfquery> <cfoutput>#getMaterialId.MaterialId#</cfoutput> <cfabort> Is it returning a value? Also, is "myPath" an absolute path in your real code? On a side note: You mentioned that you cannot know the name of the file they're uploading. Actually, you can. Once the upload takes, you can reference the name of the uploaded file (pre-upload) as #File.ClientFile#. You can reference the uploaded file (as it was named on the server) as #File.ServerFile#. |
|
#9
|
|||
|
|||
|
Actually my query was not executing correctly because it was not in the if statement. It works now. Thank you all for your wonderful advice!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Renaming an Uploaded File and Adding to Database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|