-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuploadme.cfm
More file actions
52 lines (37 loc) · 1.26 KB
/
uploadme.cfm
File metadata and controls
52 lines (37 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<cfset ui = createUUID()>
<cfset filePath = expandPath( "./" ) />
<cfscript>
function getClientFileName(fieldName) {
var tmpPartsArray = Form.getPartsArray();
var clientFileName = "";
if (IsDefined("tmpPartsArray")) {
for (local.tmpPart in tmpPartsArray) {
if (local.tmpPart.isFile() AND local.tmpPart.getName() EQ arguments.fieldName) {
return local.tmpPart.getFileName();
}
}
}
return "";
}
</cfscript>
<cfset theClientFilename = getClientFileName("file")>
<cfif ListLast(theClientFilename,".") NEQ "jpg">
// do your error handling here
<cfelse>
// else the extension is ok. Use cffile to handle the upload and proceed
</cfif>
<cfif isdefined("form.file")>
<cfset ui = createUUID()>
<cfset imgID = "" />
<cfif isdefined("url.imgID")>
<cfset imgID = url.imgID />
</cfif>
<cfset filePath = expandPath( "./" ) & "images/products/" & "#imgID#.jpg" />
<cffile action = "upload"
fileField = "file"
destination = "#filePath#"
nameConflict = "Overwrite">
<cfquery name="qry" datasource="longrun" result="qryResult">
update products set productImage = '#imgID#.jpg' where id = #imgID#;
</cfquery>
</cfif>