SunQuest
           ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old July 20th, 2004, 10:11 AM
Jazzjit Jazzjit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Lombard, IL
Posts: 28 Jazzjit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old July 20th, 2004, 10:33 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,626 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 6 m 34 sec
Reputation Power: 53
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

Reply With Quote
  #3  
Old July 20th, 2004, 11:52 AM
Jazzjit Jazzjit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Lombard, IL
Posts: 28 Jazzjit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #4  
Old July 20th, 2004, 12:01 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,626 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 6 m 34 sec
Reputation Power: 53
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.

Reply With Quote
  #5  
Old July 20th, 2004, 12:22 PM
Jazzjit Jazzjit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Lombard, IL
Posts: 28 Jazzjit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #6  
Old July 20th, 2004, 01:19 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,626 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 6 m 34 sec
Reputation Power: 53
Can you dump out form.materialID and then do a cfabort right before the cffile tag? Is it defined?

Reply With Quote
  #7  
Old July 20th, 2004, 01:44 PM
Jazzjit Jazzjit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Lombard, IL
Posts: 28 Jazzjit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #8  
Old July 20th, 2004, 02:39 PM
bfolger71 bfolger71 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Boston, MA
Posts: 47 bfolger71 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 34 sec
Reputation Power: 5
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#.

Reply With Quote
  #9  
Old July 20th, 2004, 07:07 PM
Jazzjit Jazzjit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Lombard, IL
Posts: 28 Jazzjit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Renaming an Uploaded File and Adding to Database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway