?
Solved

Get the file name and extension

Posted on 2014-04-14
3
Medium Priority
?
291 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
[X]
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
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
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 …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

762 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