ColdFusion Tutorial

Listing images on the server

This tutorial will give you a list over images *.gif, *.jpg and *.png in your images directory on your server.

If the list gives you no images, you have to change the path settings in <cfset Img_Dir? statement.
Contact your hosting company, if you not sure what is the correct path.

When you run this example, a list of all the *.jpg, *.gif and *.png images will be displayed. Click on the name of the image and the image will be displayed in your browser.

Use the <cffile tag, for delete, rename and upload new images to your server.


Example:

<!--- Set directory on your server to scan for the images.
The ExpandPath() function is used to get the absolute filesystem path on your server.
Set the name of your domain, example
www.your_domain.com  --->
<cfset domain_name = "your_domain" >
<!--- Set directory on your server to scan for the images. --->
<cfset Img_Dir = ExpandPath ("../#domain_name#/images") >
<!--- Put this test code here to check if your path settings is correct.
Comment out the lines when you have correct path.--->
<cfoutput>#Img_Dir#</cfoutput>
<cfabort>
<!--- End of comment out lines. --->
<!--- Start queries off image files. --->
<!--- Query for *.jpg files --->

<cfdirectory
   action = "List"
   directory = "#Img_Dir#"
   filter = "*.jpg"
   name = "Get_Jpg" >
<!--- Start query for *.gif files --->
<cfdirectory
   action = "List"
   directory = "#Img_Dir#"
   filter = "*.gif"
   name = "Get_Gif" >
<!--- Start query for *.png files --->
<cfdirectory
   action = "List"
   directory = "#Img_Dir#"
   filter = "*.png"
   name = "Get_Png" >
<!--- Then we use query-of-query to combine the 3 queries with SQL union, and sort the result by filename. --->
<cfquery dbtype = "query" name = "Get_Images" >
select * from Get_Jpg
union
select * from Get_Gif
union
select * from Get_Png
order by name

</cfquery>
<cfoutput>
There are #Get_Images.RecordCount# images in #Img_Dir#:
<br>
<ol>
<cfloop query = "Get_Images" >
<li> <a href = "#Img_Dir#/#name#" > #Get_Images.name# </a>
</li>
</cfloop>
</ol>
</cfoutput>

ColdFusion Tutorial test

Listing images on the server

No test is available or implemented for this ColdFusion Tutorial.

No User Comments.

No User Comments, be the first one to write your comments?

Add your comments

Your Name*:
Your Email:
Site URL:
Site Name:
Comemt Title*:
Your Comment*:
Key Phrase*:
Zi3
Your IP Address: 38.103.63.62
 

ScandicWeb is own by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.

[Home [Site Map [Privacy Statement [Site Feedback] [About ScandicWeb]


[ColdFusion [Flash [Search Engine Optimization [Graphics [Cascading Style Sheets (CSS) [JavaScript (JS) [Software]

Partner sites: ScandicSoft


Server time: 19. November 2008 Wednesday