Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Get the file name and extension

Posted on 2014-04-14
3
284 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 16

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 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