ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
Dell PowerEdge Servers
  #1  
Old May 12th, 2004, 12:42 PM
sunbigsmile sunbigsmile is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 sunbigsmile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
open window to select a picture file

Does anyone know how to create the code that will open a dialog box enabling user to select a picture file when they click on browse button?

Thanks

Reply With Quote
  #2  
Old May 12th, 2004, 02:28 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,494 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 3 Days 18 h 41 m 47 sec
Reputation Power: 45
If you mean a form field that opens a "browse local files" window so the user can pick a file, then yes. You want:

<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<input type="submit" value="Upload">
</form>

Reply With Quote
  #3  
Old May 12th, 2004, 02:28 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,494 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 3 Days 18 h 41 m 47 sec
Reputation Power: 45
Also, if you mean just opening a new browser window, you can do that in a link by adding target="_blank" to the <a> tag.

Reply With Quote
  #4  
Old May 14th, 2004, 10:22 AM
sunbigsmile sunbigsmile is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 sunbigsmile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi, Kitless
The code is working. However, if I want to store only the photo file name such as photo.jpg in the database, how can I do that? the code that you gave me will store the whole path. My purpose is the user after select his picture file from browse window, I will store that picture. Then later on when user search the information, I have to display the picture with related information.
Do you understand what I am saying. Thank you so much for your help so far.

Reply With Quote
  #5  
Old May 14th, 2004, 10:47 AM
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
Assuming you've already completed the upload with <cffile action="upload">, you can reference the filename as follows:

File.ServerFile

This is the actual name of the file saved to the server.

Reply With Quote
  #6  
Old May 14th, 2004, 12:49 PM
sunbigsmile sunbigsmile is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 sunbigsmile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi, Folger
Thank you. However, I am not quite clear of what you mean that you can reference the filename as follows:

File.ServerFile
Did you mean I should put the code :<cfoutput><img scr="#file_name.serverfile#"></cfoutput> when I want to show it?

I have to keep the exact term serverfile after dot.?
Thanks

Reply With Quote
  #7  
Old May 14th, 2004, 01:40 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,494 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 3 Days 18 h 41 m 47 sec
Reputation Power: 45
Once the file has finished uploading, you can access the name of the uploaded file at any later time during the same request. So after the file is uploaded, you could output the name of the file with:

<cfoutput>
The file just uploaded is named #cffile.serverFile#
</cfoutput>

If you want to keep the file name around for future use, you'll need to read the file name from disk, or store the file name using some persistence mechanism (database, etc.).

Reply With Quote
  #8  
Old May 18th, 2004, 11:23 AM
sunbigsmile sunbigsmile is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 sunbigsmile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I got a question. If I use cffile, do I have to store the image field in the table as OLE object. Because I set up the field name "image" in the table as text field. When user login and select the file they want to store in the database, I want to show only the file name in the field.
I used following query code
<cfquery datasource="datasource_name">
insert into user
values(userid, username, image)
</cfquery>

After that I want to display the picture that user inserted into the user table.
However, when I tested, looked at the table it did not show the image file name but instead it showed something like "C:\CFusionMX\runtime\servers\default\SERVER-INF\te". Does anyone know why is that? (P.S, I used cffile action="upload", it showed the file name when I cfoutput it by using this code
<cfoutput>
You uploaded #cffile.ClientFileName#.#cffile.ClientFileExt#
successfully to #cffile.ServerDirectory#.
</cfoutput>
Please help!!!! Thanks

Reply With Quote
  #9  
Old May 18th, 2004, 11:55 AM
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
If I understand you correctly, all you really need to do is save the filename of the image in the appropriate field of the users table, right? So (again, assuming you've already completed the upload with a CFFILE):

<cfquery datasource="datasource_name">
INSERT INTO user (userid, username, image) VALUES (#userid#, #username#, #file.ServerFile#)
</cfquery>

You're not saving the file to the database, just its name. When you want to then show it, do a query to pull the name from the DB, and code the path into your <img> call:

<cfquery name="getImageName" datasource="datasource_name">
SELECT image FROM user WHERE userid = #URL.userid#
</cfquery>

<img src="thePathToYourUploadedImages/#getImageName.image#">

Does that help?

Reply With Quote
  #10  
Old May 18th, 2004, 12:37 PM
sunbigsmile sunbigsmile is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 sunbigsmile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I can't insert the image file name
when I used the code <cfquery datasource="datasource_name">
INSERT INTO user (userid, username, image) VALUES (#userid#, #username#, #file.ServerFile#)
</cfquery
I can't show the image when I can't insert it into the DB.
Please help!
Thanks

Reply With Quote
  #11  
Old May 18th, 2004, 12:54 PM
Alas's Avatar
Alas Alas is offline
Wickedwd.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: wickedwd.com
Posts: 182 Alas Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 16 h 41 m 17 sec
Reputation Power: 0
Lightbulb Don't pay attention to me

Honestly i didn't read the whole thread, but sunbigsmile did you select OLE Object in your database?, cause (again i didn't read the whole thread ) maybe the Coldfusion is cool, but the database doesn't know your trying to insert an image (jpeg,gif,tiff, etc.)

Check you later,
Alas

Reply With Quote
  #12  
Old May 18th, 2004, 01:00 PM
sunbigsmile sunbigsmile is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 sunbigsmile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

Do I have to make that field data type into OLE object? Can I keep it as a text field and use coldfusion to develop web application?
Thanks

Last edited by sunbigsmile : May 18th, 2004 at 01:04 PM.

Reply With Quote
  #13  
Old May 18th, 2004, 01:51 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
Quote:
Originally Posted by sunbigsmile
I can't insert the image file name
when I used the code <cfquery datasource="datasource_name">
INSERT INTO user (userid, username, image) VALUES (#userid#, #username#, #file.ServerFile#)
</cfquery>

I have no idea why not. The filename is a string. Make sure the field "image" is of type "text". If you're still having issues writing to the DB, give us more details on your database and table structure.


Quote:
Originally Posted by sunbigsmile
Can I keep it as a text field and use coldfusion to develop web application?

Yes. Pull the filename from the DB. The *actual* file is being stored on the webserver somewhere (wherever you specify in the CFFILE tag). Reference that file by building the path in your <img> tag, and appending the filename you pull from the DB to the end of that path:

Quote:
Originally Posted by bfolger71
<cfquery name="getImageName" datasource="datasource_name">
SELECT image FROM user WHERE userid = #URL.userid#
</cfquery>

<img src="thePathToYourUploadedImages/#getImageName.image#">

Reply With Quote
  #14  
Old May 18th, 2004, 02:01 PM
sunbigsmile sunbigsmile is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 sunbigsmile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi, it is me again
NOw there is some improvement. When I click on get button for the images folder on the right hand side panel in dreamweaver, I saw the image was in the folder. However, the user table which stored the image file name was not storing the file name at all but this text string: C:\CFusionMX\runtime\servers\default\SERVER-INF\te.
Does any one know how to solve it. If I can store the file name, then I can show it.
Thanks

Reply With Quote
  #15  
Old May 18th, 2004, 02:09 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
Hi Sun -

Is your CFFILE tag on the same page that you're referencing FILE.ServerFile?

Can you give us your code (for the upload page) as it presently exists, so that we can take a look?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > open window to select a picture file


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