SOLUTION: The following code uploads an image and places into
the database - event tname, image name, image height, image height,
and text for a caption to go with the image.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<html>
<head>
<title>Upload Event Photos</title>
<link rel=stylesheet type="text/css" href="style.css">
<cfscript>
/**
* Returns width and height of images based on image type.
*
* @param filename Absolute or relative path to file.
(Required)
* @param mimetype Minetype for the file. (Optional)
* @return Returns a struct containing height and width
information, or an error string.
* @author Peter Crowley
(pcrowley@webzone.ie)
* @version 1, August 17, 2006
*/
function ImageSize(filename) {
// Jpeg variables
var nFileLength=0; var nBlockLength=0; var nMarker=0;
var nSOI = 65496; // Start of Image (FFD8)
var nEOI = 65497; // End of Image (FFD9)
var nSOF = 65472; // Start of frame nMarker (FFC0)
var nSOF1 = 65473; // Start of frame extended sequential
mode (FFC1)
var nSOF2 = 65474; // Start of frame progressive mode (FFC2)
var nSOF3 = 65475; // Start of frame lossless mode (FFC3)
var nSOS = 65498; // Start of Scan (FFDA)
var sImageType = "";
var kCoords = structNew();
var fInput = 0;
var sByte=0;
var sFullPath="";
var sMimeType = "";
if (Left(filename,1) IS "/" OR Left(filename,1) IS "\" OR
MID(filename,2,1) IS ":")
sFullPath=filename;
else
sFullPath=ExpandPath(filename);
// Establish image type
if(arrayLen(arguments) gt 1) { //optional mimetype
sMimeType = arguments[2];
if (LCase(ListFirst(sMimeType,"/")) IS NOT "image") return
"Wrong mime type";
if (ListLen(sMimeType,"/") NEQ 2) return "Invalid mime
type";
sImageType=LCase(ListLast(sMimeType,"/"));
} else { // work off file extension
if (ListLen(filename,".") LT 2) return "Unknown image type";
sImageType=LCase(ListLast(filename,"."));
}
if(not fileExists(sFullPath)) return "File does not exist.";
//make a fileInputStream object to read the file into
fInput =
createObject("java","java.io.RandomAccessFile").init(sFullPath,"r");
// Get X,Y resolution sizes for each image type supported
switch (sImageType) {
case "jpg": case "jpeg":
do {
nMarker = fInput.readUnsignedShort();
if (nMarker NEQ nSOI AND nMarker NEQ nEOI AND nMarker NEQ
nSOS) {
nBlockLength = fInput.readUnsignedShort();
if (nMarker EQ nSOF OR nMarker EQ nSOF1 OR nMarker EQ nSOF2
OR nMarker EQ nSOF3) { // Start of frame
fInput.readUnsignedByte(); // skip sample precision in bits
kCoords.ImageHeight = fInput.readUnsignedShort();
kCoords.ImageWidth = fInput.readUnsignedShort();
fInput.close();
return kCoords;
} else {
fInput.skipBytes(JavaCast("int",nBlockLength-2));
}
}
} while (BitSHRN(nMarker,8) EQ 255 AND nMarker NEQ nEOI);
break;
case "gif":
fInput.skipBytes(6);
sByte = fInput.readUnsignedByte();
kCoords.ImageHeight = fInput.readUnsignedByte() * 256 +
sByte;
sByte = fInput.readUnsignedByte();
kCoords.ImageWidth = fInput.readUnsignedByte() * 256 +
sByte;
fInput.close();
return kCoords;
default:
break;
}
//close out this entry
fInput.close();
return "Unhandled image type";
}
</cfscript>
</head>
<body bottommargin="0" leftmargin="0" rightmargin="0"
topmargin="0" background="../img/background.jpg">
<!-------- page data goes below here ------>
<!--------------->
<div align="center"><h1><font
color="#FF0000">Database
Maintenance</font></h1></div>
<br><br><br>
<br><br>
<div align="center"><table border="2"
width="100">
<tr>
<td>
<div align="center">Click here to upload a new Event
Photo:
<cfif isdefined("form.upload_now")>
<cffile action="upload" filefield="ul_path" destination=
"C:\CFusionMX7\wwwroot\aasr\eventpics\"
nameconflict="overwrite">
<cfset newfile = #cffile.serverfile#>
<CFSCRIPT>
kImageSize = ImageSize("#newfile#");
</CFSCRIPT>
<cfquery name="insert_eventpics" datasource="gph">
insert into eventpics
(eventname, picpath, imageheight, imagewidth, pictext)
values
('#eventname#', '#newfile#', '#kImageSize.ImageHeight#',
'#kImageSize.ImageWidth#', '#pictext#')
</cfquery>
</cfif>
<form action="" method="post" name="upload_form"
enctype="multipart/form-data" id="upload_form">
<input type="File" name="ul_path" size="40"
id="ul_path">
</td>
</tr>
<tr>
<td>
Event name: <input type="text" name="eventname"
id="eventname" size="40">
</td>
</tr>
<tr>
<td>
Picture text: <input type="text" name="pictext"
id="pictext" size="40">
</td>
</tr>
<tr>
<td>
<div align="center"><input type="submit"
name="upload_now" value="Submit"></div>
</td>
</tr>
</form>
</table>
</div>
<!-------- page data goes above here ------>
<!--------------->
</body>
</html>