[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Get the file name and extension

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
lulu50
Asked:
lulu50
1 Solution
 
gdemariaCommented:
<cfset theFileName = getFileFromPath(qGetFile.UploadedFile)>
<cfset theFileExt  = listLast(theFileName,".")>
0
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
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
 
lulu50Author Commented:
Thank you.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now