Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server file or image extension 1

Status
Not open for further replies.

idanner

Programmer
Aug 30, 2004
17
US
How can I get the correct extension of the image that was uploaded to my server. I don't want the client file extension because I'm renaming the image and I need the ext. of whatever was uploaded.
Here is the code to save and then rename.
Code:
<cffile action="upload"
			destination="#thisPath#"
			nameConflict= "overwrite"
			fileField="Form.FiletoUpload" accept="image/gif, image/pjpeg, image/jpg">			
		
			<cfif fileWasSaved>      
			  <cffile action="rename"
				source="#ServerDirectory#\#cffile.ClientFileName#.#cffile.ClientFileExt#"
				destination="#thisPath##officeimg.Name#.jpg">		
			</cfif>

Here is how I'm displaying the images.I can only display jpgs now.
Code:
<CFIF Fileexists(ExpandPath("/nicolecfsite/OnlineDir/images/#Contacts.Username#.jpg"))>		
							<img src="./images/#Contacts.Username#.jpg" height="120" width="120" 
							border="none" >

Thanks for any help.

 
listLast(cffile.serverfile, ".") should do it for ya.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Thanks bombboy for the tip. Although the tip didn't work for me because I'm displaying the images on another page besides the cffile form page, I'm sure it would work from that page. If I did it wrong or if there is another way to get the ext. from a saved file off the server then let me know. Thank you.
 
You're not being very clear... I read this earlier and couldn't make much sense of it..

I think you mean that the problem is you're storing the filenames in a database by username or something.. and on display, you can't figure out how to get the correct extension..

You have two methods.. Either store the extension in the table with the usernames or whatever (in a different column if you like). Or Use FileExists.

Code:
<cfif fileexists(expandpath("#username#.jpg"))>
  <img src="./images/#Contacts.Username#.jpg" height="120" 
   width="120" border="none">
<cfelseif fileexists(expandpath("#username#.gif"))>
  <img src="./images/#Contacts.Username#.gif" height="120" 
   width="120" border="none">
<cfelseif fileexists(expandpath("#username#.png"))>
  <img src="./images/#Contacts.Username#.png" height="120" 
   width="120" border="none">
<cfelse>
  Image does not exist.
</cfif>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Thank you very much webmigit. That is exactly what I was looking for.
 
Not a problem, have a good night.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top