|
|
Server Time: Monday May 12 2008 06:55 AM |
|
Your Time: |
First off create a database called Images and 3
fields called
image_id (Autonumber)
links (text)
picture (text)
Then do the following:
Default.cfm
<!--- get the images and stroe into memory --->
<cfquery name="qGetImages"
datasource="Image">
SELECT picture, descrip, link
FROM images
ORDER BY image_id
</cfquery>
<!--- catch queries with no values --->
<cfif qGetImages.RecordCount>
<!--- pick a random image from the
query --->
<cfset current_image = RandRange(1,
qGetImages.RecordCount)>
<cfoutput>
<table>
<tr>
<td><a href="#qGetImages.link[current_image]#"
target="_self"><img src="http://localhost/Images/#qGetImages.picture[current_image]#"
border="0" alt="
Image "></a></td>
</tr>
<tr>
<td><a href="#qGetImages.link[current_image]#">#qGetImages.descrip[current_image]#</a></td>
</tr>
</table>
</cfoutput>
<cfelse>
<!--- no images found, display the
default image instead --->
<img src="default.gif"
border="0" alt="
Default Image ">
</cfif>
delete.cfm
<cfquery name="qDelete"
datasource="Image">
DELETE picture, descrip, link
FROM images
WHERE image_id = #id#
</cfquery>
form.cfm
<form action="upload_action.cfm"
method="POST" enctype="multipart/form-data"
name="contact"
onsubmit='return checkForm();'>
<div>
<TABLE BORDER="0"
bgcolor="#ffffff">
<TR>
<TD>Browse for Image File:</TD>
<TD><input name="picture"
size="53" type="file"
value=""></TD>
<tr>
<td>Type in Description:</TD>
<TD><textarea name="descrip"
rows="7" cols="50"></textarea></TD>
<TR>
<TD>Type in hyperlink:</TD>
<TD><input type="text"
name="link" size="66"></TD>
</TR>
<TR>
<TD COLSPAN="2"><input
type="Submit" value="Insert"></td>
</tr>
</TABLE>
</div>
</form>
<BR><BR>
<cfinclude template ="list.cfm">
list.cfm
<cfquery name="qGetImages"
datasource="Image">
SELECT picture, descrip, link, image_id
FROM images
ORDER BY image_id
</cfquery>
<!--- Now display the records to the user --->
<HR>
<cfoutput query="qGetImages">
<table>
<tr><td><img src="http://localhost/Images/#qGetImages.picture#"
border="0" alt="
Image "></td></tr>
<tr><td>#picture#</td></tr>
<tr><td>#descrip#</td></tr>
<tr><td>>#link#</td></tr>
</table>
<a href="delete.cfm?id=#image_id#"
onClick="return confirm('Are You Sure You Want To
Delete This Record?');">DELETE</a>
<HR>
</cfoutput>
upload_action.cfm
<cfif picture NEQ ''>
<CFFILE ACTION="upload"
FILEFIELD="picture"
DESTINATION="E:\webserver\Images\"
NAMECONFLICT="MAKEUNIQUE">
<cfset upload= #file.serverfile#>
<cfoutput>
#serverFile# successfully added. Size
of the uploaded file:
#Numberformat(Evaluate(File.FileSize/1024))# KB.</cfoutput>
</cfif>
<br>
<cfquery name="InsertDetails"
datasource="Image">
INSERT INTO Images (picture, descrip, link)
VALUES ('#listLast(file.serverFile, '\')#', '#form.descrip#',
'#form.link#')
</cfquery>
Date added: Fri. July 25, 2003
Posted by: Chris | Views: 10196 | Tested Platforms: CF5 | Difficulty: Intermediate
Full Applications
 |
please fix this one..
hi..cj.. i always enjoy your tutorial...even now.. but i do found above code not really work please correct them with all possible... if got time..:(
thanks you
arthur
Posted by: arthur
Posted on: 01/05/2005 02:18 AM
|
What's wrong?
What is wrong with the tutorial?
Posted by: sparty2809
Posted on: 01/05/2005 06:33 AM
|
thanks for reply
hi sparty..
i got error message said too few paramenter .exptect 1 in list.cfm line 9 and line 11 in default.cfm <cfquery name = "qGetImages" datasource="image"
don't know what can i do...about it :(
Posted by: arthur
Posted on: 01/06/2005 12:38 AM
|
DSN
Is your DSN called image? Also you need a > at the end to close the tag.
Posted by: sparty2809
Posted on: 01/06/2005 06:32 AM
|
This works great....
I tried this....& it works good...
Posted by: Vamsidar Reddy Malgireddy
Posted on: 01/28/2005 04:14 PM
|
i have some quries
Can you tell me how to create below generated image with random text to user. As below you had shown can you send me document code which i am using coldfusion 5.0
Regards, Vivek
Posted by: vivek nanda
Posted on: 03/09/2006 04:50 AM
|
Different images for each table cell
now how would i modify this code for three table cells to bring up different images for each cell? from the database and select one category of images for each page
Table categories in db Illustrations Photos Paintings
Posted by: Bruce James
Posted on: 04/02/2006 12:58 AM
|
|
|
|
|
|
|
|