Solved

Get the file name and extension

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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