Solved

Get the file name and extension

Posted on 2014-04-14
3
280 Views
Last Modified: 2014-04-16
Hi,

I need to get the file name and it's extension.

this is my code:

      <cfquery name = "QGetFile"  datasource='#strDSN#' username='#strUID#' password='#strPWD#' result="file">
			select FileID, FileName,UploadedFile,uploadedasbinary from Files
			where IssueID = #url.ID#
		</cfquery>

 <cfloop query="QGetFile">  
      <cfloop index="k" list="#QGetFile.columnList#">
        <cfset form[k & QGetFile.currentRow] = QGetFile[k][QGetFile.currentRow]>
      </cfloop>
 </cfloop>


I want to get the file extension and file name from this field.
#QGetFile.UploadedFile#


 <cfoutput>
                 <cfloop from="1" to="#val(form.recordCount)#" index="ii"> 
  
            <cfset convertfile[ii] =  #tostring(tobinary(Form["UploadedFile" & ii]))#>
            <cfset fileName[ii] = #ListLast(convertfile[ii],"\")#>
	<cfset fileExtension[ii] = #ListLast(convertfile[ii],".")#> 

                  <tr>        
                  <td style="width:120px;float:right;padding-right:5px;" align="right">View File
                  </td>
                    <td colspan="2" align="left" valign="top" style="padding-right:5px;">             
                         <cfswitch expression="#fileExtension[ii]#"> 
    				<cfcase value="GIF">
        	 		<a href="javascript:void(0);" onclick="window.open('http://budv/mpdb/impact/UploadedFiles/#fileName[ii]#',640,480); return false;" >
                 #fileName[ii]#</a>
    				</cfcase>
    				<cfcase value="TIF">
        		 	  <a href="javascript:void(0);" onclick="window.open('http://budv/mpdb/impact/UploadedFiles/#fileName[ii]#',640,480); return false;" >
                 #fileName[ii]#</a>
   	 				</cfcase>
    				<cfcase value="PNG">
        		 <a href="javascript:void(0);" onclick="window.open('http://budv/mpdb/impact/UploadedFiles/#fileName[ii]#',640,480); return false;" >
                 #fileName[ii]#</a>
    				</cfcase>
    				<cfcase value="JPG">
        		  <a href="javascript:void(0);" onclick="window.open('http://budv/mpdb/impact/UploadedFiles/#fileName[ii]#',640,480); return false;" >
                 #fileName[ii]#</a>
    				</cfcase>
        			<cfcase value="JPEG">
        		  <a href="javascript:void(0);" onclick="window.open('http://budv/mpdb/impact/UploadedFiles/#fileName[ii]#',640,480); return false;" >
                 #fileName[ii]#</a>
    				</cfcase>
					<cfdefaultcase>
				<a href="UploadedFiles/#fileName[ii]#" >#fileName[ii]#</a><br /><br />
 					</cfdefaultcase> 
				</cfswitch>
                 </tr>

</cfloop>

</cfoutput>

Open in new window

0
Comment
Question by:lulu50
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 39999979
<cfset theFileName = getFileFromPath(qGetFile.UploadedFile)>
<cfset theFileExt  = listLast(theFileName,".")>
0
 
LVL 15

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40002010
Have not seen the entire code, but this will work too:

<cfset theFileName = qGetFile.UploadedFile>

Open in new window


You need not add getFileFromPath if you just name the file name


you can use this UDF to get the extenstion and place it somewhere in your application.cfm to reuse it anywhere you like

http://www.cflib.org/udf/getExtension

@gdemaria - Answer he gave is correct, mine is just an extension if you need to make some generic to use in anywhere you want to..
0
 

Author Closing Comment

by:lulu50
ID: 40003910
Thank you.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now