Hey guys i am stuck at a point .I have a situation where i need to upload the scaled image in different folder for example :- 1(small).jpg on small folder , 1(medium).jpg on medium folder and 1.jpg on uploads folder. Right now the code below is uploading all 3 images on different folders but the files are blob files.How to get the scaled image . (edited the code)
<cfset destinationDirectory = expandpath('/file_uploader/uploads')>
<cfset counter = 1>
<cfset uniqueFileName = "">
<cfset destinationFilePath = "">
<cfset smallfile = "">
<cfset mediumfile ="">
<cfset mainfile= ''>
<cfscript>
variables.validMimeTypes = {'image/jpeg': {extension: 'jpg'}
,'image/png': {extension: 'png'}
,'image/png': {extension: 'gif'}
}; </cfscript>
<cftry>
<cfset cnt= 1>
<cfset file_name = #qqfilename#>
<cfset file_size = #qqtotalfilesize#>
<!--- If a file with the same name already exists at the destination --->
<cfif fileExists(destinationDirectory & "/" & file_name)>
<!--- Loop up to 100 times to try create a unique file_name --->
<cfset destinationFilePath = destinationDirectory & "/" & counter & "_" & file_name>
<!--- Loop up to 100 times to try create a unique filename --->
<cfloop condition="counter LT 100">
<cfset destinationFilePath = destinationDirectory & "/" & counter & "_" & file_name>
<cfif fileExists(destinationFilePath)>
<cfset counter++>
<cfelse>
<cfset uniqueFileName = "IMG" & counter & "_" & file_name>
<cfbreak/>
</cfif>
</cfloop>
<!--- Filename does not already exist at the destination --->
<cfelse>
<cfset uniqueFileName = "IMG" & "_" & file_name>
<cfset destinationFilePath = destinationDirectory & "/" & file_name>
</cfif>
<cfif len(trim(uniqueFileName))>
<cfset session.cntr ++>
<cfif find("(small)",file_name) neq 0>
<cfset smallfile = file_name>
<cffile
action="upload"
destination="#UploadPath2#"
accept="#StructKeyList(variables.validMimeTypes)#"
nameconflict="#smallfile#"
>
<cfelseif find("(medium)",file_name) neq 0>
<cfset mediumfile = file_name>
<cffile
action="upload"
filefield="qqfile"
destination="#UploadPath1#"
accept="#StructKeyList(variables.validMimeTypes)#"
nameconflict="#uniqueFileName#"
>
<cfelse>
<cfset mainfile= file_name>
<cffile
action="upload"
filefield="qqfile"
destination="#destinationFilePath#"
accept="#StructKeyList(variables.validMimeTypes)#"
nameconflict="#uniqueFileName#"
>
</cfif>
<CFSET local.response['success'] = true >
<CFSET local.response['type'] = 'xhr' >
<CFSET local.response['obj'] = session.cntr >
<cfelse>
<CFSET local.response['error'] = 'Unable to move the file and create a unique file_name at the destination'>
</cfif>
<cfoutput>
#serializeJSON(local.response,true)#
</cfoutput>
<cfabort/>
<cfcatch type="any">
<cfoutput> #serializeJSON(session.cntr,true)# </cfoutput>
<cfabort/>
</cfcatch> </cftry>
below is the UI page
<!DOCTYPE html> <html> <head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- jQuery
====================================================================== -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Fine Uploader Gallery CSS file
====================================================================== -->
<link href="../file_uploader/includes/fine-uploader-gallery.css" rel="stylesheet">
<!-- Fine Uploader JS file
====================================================================== -->
<script src="../file_uploader/includes/all.fine-uploader.js"></script>
<script src="../file_uploader/includes/all.fine-uploader.min.js"></script>
<script src="../file_uploader/includes/jquery.fine-uploader.js"></script>
<script src="../file_uploader/includes/jquery.fine-uploader.min.js"></script>
<!-- Fine Uploader Gallery template
====================================================================== -->
<script type="text/template" id="qq-template-gallery">
<div class="qq-uploader-selector qq-uploader qq-gallery" qq-drop-area-text="Drop files here">
<div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container">
<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div>
</div>
<div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
<span class="qq-upload-drop-area-text-selector"></span>
</div>
<div class="qq-upload-button-selector qq-upload-button">
<div>Upload a file </div>
</div>
<span class="qq-drop-processing-selector qq-drop-processing">
<span>Processing dropped files...</span>
<span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
</span>
<ul class="qq-upload-list-selector qq-upload-list" role="region" aria-live="polite" aria-relevant="additions removals">
<li>
<span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
<div class="qq-progress-bar-container-selector qq-progress-bar-container">
<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-progress-bar-selector qq-progress-bar"></div>
</div>
<span class="qq-upload-spinner-selector qq-upload-spinner"></span>
<div class="qq-thumbnail-wrapper">
<img class="qq-thumbnail-selector" qq-max-size="120" qq-server-scale>
</div>
<button type="button" class="qq-upload-cancel-selector qq-upload-cancel">X</button>
<button type="button" class="qq-upload-retry-selector qq-upload-retry">
<span class="qq-btn qq-retry-icon" aria-label="Retry"></span>
Retry
</button>
<div class="qq-file-info">
<div class="qq-file-name">
<span class="qq-upload-file-selector qq-upload-file"></span>
<span class="qq-edit-filename-icon-selector qq-edit-filename-icon" aria-label="Edit filename"></span>
</div>
<input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
<span class="qq-upload-size-selector qq-upload-size"></span>
<button type="button" class="qq-btn qq-upload-delete-selector qq-upload-delete">
<span class="qq-btn qq-delete-icon" aria-label="Delete"></span>
</button>
<button type="button" class="qq-btn qq-upload-pause-selector qq-upload-pause">
<span class="qq-btn qq-pause-icon" aria-label="Pause"></span>
</button>
<button type="button" class="qq-btn qq-upload-continue-selector qq-upload-continue">
<span class="qq-btn qq-continue-icon" aria-label="Continue"></span>
</button>
</div>
</li>
</ul>
<dialog class="qq-alert-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<div class="qq-dialog-buttons">
<button type="button" class="qq-cancel-button-selector">Close</button>
</div>
</dialog>
<dialog class="qq-confirm-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<div class="qq-dialog-buttons">
<button type="button" class="qq-cancel-button-selector">No</button>
<button type="button" class="qq-ok-button-selector">Yes</button>
</div>
</dialog>
<dialog class="qq-prompt-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<input type="text">
<div class="qq-dialog-buttons">
<button type="button" class="qq-cancel-button-selector">Cancel</button>
<button type="button" class="qq-ok-button-selector">Ok</button>
</div>
</dialog>
</div>
</script>
<title>Fine Uploader Gallery View Demo</title> </head> <body>
<!-- Fine Uploader DOM Element
====================================================================== -->
<div id="fine-uploader-gallery"></div>
<!-- Your code to create an instance of Fine Uploader and bind to the DOM/template
====================================================================== -->
<script> var posturl = "../file_uploader/upload_file.cfm"; var t= 0;
var galleryUploader = new qq.FineUploader({
element: document.getElementById("fine-uploader-gallery"),
//debug: true,
autoUpload: false,
template: 'qq-template-gallery',
request:
{
// endpoint: '../file_uploader/upload_file.cfm?id=<cfoutput>#session.cntr#</cfoutput>'
endpoint: posturl
},
thumbnails:
{
placeholders:
{
waitingPath: '../file_uploader/includes/placeholders/waiting-generic.png',
notAvailablePath: '../file_uploader/includes/placeholders/not_available-generic.png'
}
},
validation:
{
allowedExtensions: ['jpeg', 'jpg', 'gif', 'png']
},
callbacks: {
onComplete: function(id, name, responseJSON , xhrOrXdr)
{
if (responseJSON.success)
{
t++;
alert("success"+t);
uploadSuccess: {
endpoint: "../file_uploader/upload_file.cfm?id=1"
}
}
},
onError: function(id, name, errorReason, xhrOrXdr)
{
alert(qq.format("Error on file number {} - {}. Reason: {}", id, name, errorReason));
}
},
scaling:
{
//hideScaled: true,
sizes:
[
{name: "small", maxSize: 100},
{name: "medium", maxSize: 300}
]
}
});
</script> </body> </html>
There are at least two ways to determine the scaled size of an image. One way would be to look for the appropriate prefix in the image's file name. For example, if you've instructed Fine Uploader to include the phrase "small", then you should look for the string "(small)" in the file name server-side. The same goes for any other size prefix you have specified in your scaling options.
Another option would be to look at the actual size of the files in a scaling group. Each scaled file in a group will contain a qqparentuuid request parameter pointing to the UUID of the original image/file. Once you have all of these files, you can examine their sizes to determine which one is small, medium, large, etc.
I highly suggest using the first option.
Related
I have output from a table that I want highlighted should a certain requirement not be met. I have it working fine for one section, but then when I use the code on a QofQ after an inner join of two tables, it doesn't work.
I can see when I dump the variables that they are correct and I know 100% that one of the companies contains no negative data so should display correctly but both companies are displaying in red.
I'm obviously not seeing something or does QofQ have limitations that are causing this ?
I'm still learning so please be kind :)
Queries :
<cfquery name="suppNeg" datasource="users">
SELECT companies.subID, companies.companyID, companies.suppName
, suppresult_old.companyID, suppresult_old.O18, suppresult_old.O19
, suppresult_old.O20, suppresult_old.O22, suppresult_old.WDPVC1
, suppresult_old.WDPVC2, quarterID
FROM suppresult_old INNER JOIN companies
ON suppresult_old.companyID=companies.companyID
WHERE quarterID = 8
AND companies.subID = #session.auth.companyID#
ORDER BY companies.suppName ASC
</cfquery>
<cfquery dbtype="query" name="subs">
SELECT DISTINCT suppName, companyID, subID
FROM suppNeg
ORDER BY suppName ASC
</cfquery>
<cfquery name="columntotals" datasource="users">
SELECT O18,O19,O20,O22, WDPVC1, WDPVC2
FROM suppresult_old INNER JOIN companies
ON suppresult_old.companyID=companies.companyID
WHERE quarterID = 8
AND companies.subID = #session.auth.companyID#
</cfquery>
<cfset O18Value = valueList(columntotals.O18) />
<cfset O18total = listToArray(O18Value) />
<cfset O19Value = valueList(columntotals.O19) />
<cfset O19total = listToArray(O19Value) />
<cfset O20Value = valueList(columntotals.O20) />
<cfset O20total = listToArray(O20Value) />
<cfset O22Value = valueList(columntotals.O22) />
<cfset O22total = listToArray(O22Value) />
<cfset WDPVC1Value = valueList(columntotals.WDPVC1) />
<cfset WDPVC1total = listToArray(WDPVC1Value) />
<cfset WDPVC2Value = valueList(columntotals.WDPVC2) />
<cfset WDPVC2total = listToArray(WDPVC2Value) />
<cfquery name="suppliers" datasource="users">
SELECT suppName, companyID, subID
FROM companies
WHERE subID=#session.auth.companyID#
ORDER BY suppName ASC
</cfquery>
Output :
<cfoutput query="subs">
<div class="container" width="1100">
<div class="row">
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfif (arraysum(O18total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong></a>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(O19total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(O20total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(O22total)) lt 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(WDPVC1total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(WDPVC2total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<cfelse>
<a href="suppReports_admin.cfm?quarterID=8&companyID=#companyID#">
<div class ="col-sm-4 supphighlight">
<h4>
<span class="glyphicon glyphicon-ok-circle" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
....
That's a lot to digest, without any data samples, but I'll take a stab at it :) I think the problem is that the code is comparing apples and oranges. The "sub" query contains the details for individual companies and subId's. (I've no idea what the real data looks like, so the samples below are just for illustration)
However, the cfif comparisons calculate the overall total for all companies and subId's. So if the overall total for O20 (O18, etc..) is negative, then it'll be negative for every company in the cfoutput.
Runnable TryCF.com Example
If all you want is the totals, by companyId and subId, it's much easier to calculate that in SQL. Instead of all the ValueList(), ArraySum() and QoQ's, use the SQL aggregate function SUM(). I don't know which DBMS you're using, but something like this should work in most any database:
Note: I "guessed" that quarterID is a column in the suppresult_old table
<!--- NOT TESTED --->
<cfquery name="totalsByCompany" datasource="users">
SELECT companies.subID
, companies.companyID
, companies.suppName
, suppresult_old.quarterID
, SUM(suppresult_old.O18) AS O18Total
, SUM(suppresult_old.O19) AS O19Total
, SUM(suppresult_old.O20) AS O20Total
, SUM(suppresult_old.O22) AS O22Total
, SUM(suppresult_old.WDPVC1) AS WDPVC1Total
, SUM(suppresult_old.WDPVC2) AS WDPVC2Total
FROM suppresult_old
INNER JOIN companies ON suppresult_old.companyID=companies.companyID
WHERE suppresult_old.quarterID = 8
AND companies.subID= <cfqueryparam value="#session.auth.companyID#" cfsqltype="cf_sql_integer">
GROUP BY companies.subID
, companies.companyID
, companies.suppName
, suppresult_old.quarterID
ORDER BY companies.suppName ASC
</cfquery>
Then in your cfoutput, use the calculated SUM's:
<cfoutput query="totalsByCompany">
....
<cfif O18total LT 0> .... code here
<cfelseif O19total LT 0>.... code here
<cfelse> ...
</cfif>
</cfoutput>
Aside: If you're new to S.O., might want to take a gander at How to create a Minimal, Complete, and Verifiable example. Putting together (the smallest possible) self-contained example demonstrating the problem makes it a LOT easier for others to assist, and less likely the question will be closed as too broad :) Also, tools like https://trycf.com and https://sqlfiddle.com are great for sharing runnable examples.
Disclaimer, I'm a ColdFusion newbie...
I'm using Mura CMS 6, and I've got a question with regards to accessing a custom attribute.
My contentRenderer.cfc file has code for a Bootstrap Carousel. I'd like to be able to output the contents of a custom attribute on the file that the carousel is using, but I'm not entirely sure how to do that.
My custom attribute is named 'imageLink', but I have no idea how to get the current context to be able to output the contents of this attribute to the screen.
The following code is the code for the carousel (I didn't write it)
<cfsavecontent variable="local.str"><cfoutput>
<!--- BEGIN: Bootstrap Carousel --->
<!--- IMPORTANT: This will only output items that have associated images --->
<cfset local.feed = variables.$.getBean('feed').loadBy(name=arguments.feedName)>
<cfset local.iterator = local.feed.getIterator()>
<cfif local.feed.getIsNew()>
<div class="container">
<div class="alert alert-info alert-block">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
<h4>Ooops!</h4>
The <strong>#HTMLEditFormat(arguments.feedName)#</strong> Content Collection/Local Index does not exist.
</div>
</div>
<cfelseif local.iterator.hasNext()>
<div id="#arguments.cssID#" class="carousel slide" data-interval="#arguments.interval#">
<!--- Indicators --->
<cfif arguments.showIndicators>
<ol class="carousel-indicators">
<cfset local.iterator.reset()>
<cfset local.idx = 0>
<cfloop condition="local.iterator.hasNext()">
<cfset local.item=iterator.next()>
<cfif ListFindNoCase('jpg,jpeg,gif,png', ListLast(local.item.getImageURL(), '.'))>
<li data-target="###arguments.cssID#" data-slide-to="#idx#" class="<cfif local.idx eq 0>active</cfif>"></li>
<cfset local.idx++>
</cfif>
</cfloop>
</ol>
</cfif>
<!--- Wrapper for slides --->
<div class="carousel-inner" role="listbox">
<cfset local.iterator.reset()>
<cfset local.idx = 0>
<cfloop condition="local.iterator.hasNext()">
<cfset local.item=iterator.next()>
<cfif ListFindNoCase('jpg,jpeg,gif,png', ListLast(local.item.getImageURL(), '.'))>
<div class="item<cfif local.idx eq 0> active</cfif>">
<img src="#local.item.getImageURL(argumentCollection=local.imageArgs)#" alt="#HTMLEditFormat(local.item.getTitle())#">
<cfif arguments.showCaption>
<div class="container">
<div class="carousel-caption">
<h2>#HTMLEditFormat(local.item.getTitle())#</h2>
#local.item.getTitle()#
<!-- <p><a class="btn btn-larg btn-primary" href="#local.item.getURL()#">Read More</a></p>-->
</div>
</div>
</cfif>
</div>
<cfset local.idx++>
</cfif>
</cfloop>
</div>
<cfif local.idx>
<!--- Controls --->
<cfif local.idx gt 1>
<a class="left carousel-control" href="###arguments.cssID#" data-slide="prev" role="button">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="###arguments.cssID#" data-slide="next" role="button">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<!--- AutoStart --->
<cfif arguments.autoStart>
<script>jQuery(document).ready(function($){$('###arguments.cssID#').carousel({interval:#arguments.interval#});});</script>
</cfif>
</cfif>
<cfelse>
<div class="alert alert-info alert-block">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
<h4>Oh snap!</h4>
Your feed has no items <em>with images</em>.
</div>
</cfif>
</div>
<cfelse>
<div class="alert alert-info alert-block">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
<h4>Heads up!</h4>
Your feed has no items.
</div>
</cfif>
<!--- // END: Bootstrap Carousel --->
</cfoutput></cfsavecontent>
How can I access the current context to output that attribute?
Here are the docs on how to display them.
http://docs.getmura.com/v6/back-end/class-extension-manager/displaying-extended-attributes/
It looks like you looping through a collection of content so I believe this would work.
#local.item.get("imageLink")#
Assuming you are working within the cfloop and after the line
<cfset local.item=iterator.next()>
You can get your custom imageLink value using
#local.item.getImageLink()#
or
#local.item.getValue('imageLink')#
I'm trying to work these cookies so once the user/pass is correct it will start a cookie for the user to always show the username when logging back in (remember me feature).
While this code gave the "usernameCookie" value when I checked it at the same page, it didn't pass it to the next one. It's like it doesn't exist anymore. Of course, I used buffer=true but this is driving me crazy why it doesn't work.
<%# language="VBscript"%>
<% response.buffer = True %>
<!-- #include file = "ddsn.asp" -->
<!-- #include file = "sfuncs.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<!--Initiate form validation - in this example on the login form-->
<script type="text/javascript">
$(document).ready(function() {
$("#loginform").validate();
});
</script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
msg = ""
If request.form ("password") <> "" Then
Set rs = Server.CreateObject("ADODB.RecordSet")
SQL = "Select id,firstName,lastName,username,password,permissions,status FROM dispatchersTBL WHERE username='" & request.form ("username") & "' and password='" & request.form ("password") & "'"
If inStr(1,SQL,";") or inStr(1,SQL,"''") OR inStr(1,LCase(SQL)," or ") Then msg = "<strong>Wrong Username or Password</strong>" End If
rs.Open SQL,SQLDSN,3,1
If NOT rs.EOF Then
Session("login") = "True"
Session("loggedUserID") = rs("id")
Session("fullName") = rs("firstName") & " " & rs("lastName")
Session("permissions") = rs("permissions")
status = rs("status")
Session.Timeout = 1440
If status = "Inactive" Then
msg = "<p><strong>Inactive User. Please contact the administrator.</strong></p>"
Else
response.cookies("usernameCookie") = rs("username")
response.cookies("passwordCookie") = rs("password")
response.cookies("usernameCookie").expires = Date() + 30
response.cookies("passwordCookie").expires = Date() + 30
response.redirect adminSiteURL & "co-worker-sms.asp"
End If
Else
msg = "<p><strong>Wrong Username or Password</strong></p>"
End if
rs.Close
Set rs = Nothing
End if
%>
<div id="admin_wrapper">
<form action="default.asp" id="login" method="post">
<%=msg%>
<!-- TEXTBOXES -->
<label>Username</label><br />
<input name="username" type="text" value="<%=request.cookies("usernameCookie")%>" class="text large required" id="username" /><br />
<div class="clearfix"> </div>
<label>Password</label><br />
<input name="password" type="password" value="<%=request.cookies("passwordCookie")%>" class="text large required" id="password" /><br />
<div class="clearfix"> </div>
<p><input name="btnLogin" type="submit" class="submit" id="btnLogin" value="LOGIN" /></p>
</form>
</div>
</body>
</html>
What am I missing?
I haven't seen your login page but your code seems ok - are you sure you do the request.cookies when you try to retrieve it ?
try make a simple page like this
<%
' put cookie
Response.Cookies("usernameCookie") = "Superman"
Response.Cookies("usernameCookie").Expires = Date() + 10
Response.Cookies("passwordCookie") = "Batman"
response.Cookies("passwordCookie").Expires = Date() + 10
%>
<% ' Print my cookie %>
<input type="text" value="<% = request.cookies("usernameCookie") %>" name="username">
<br />
<input type="text" value="<% = request.cookies("passwordCookie") %>" name="password">
After a reload page your input fields should have "superman" an "batman"
I am trying to create a form where by the user selects a location where they then upload a document using CFFILE ACTION ="UPLOAD". I am not great at this so any help you could provide would be greatly appreciated.
Below is my code. Essentially, there is a dropdown list of folder locations. The user first selects one of the locations. Then clicks 'browse' to choose a file. Finally they click submit and the file uploads.
The code that is #dir# is the folder location that is linked to each of the location names. What is happening at the moment is that the document gets uploaded successfully... but it is uploading to all the folder locations instead of the one that is selected from the dropdown. Here is my code:
docuploads.cfm
<cfquery name="getLocation">
SELECT *
FROM Locations
ORDER BY FolderName
</cfquery>
<form action="docuploads.cfm" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form">
<select name="folderID">
<option value="">--- Select Folder ---</option>
<cfoutput query="getLocation">
<option value="#FolderName#"">#FolderName#</option>
</cfoutput>
</select>
<cfoutput query="getLocation">
<CFIF IsDefined("form.upload_now")>
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<CFFILE ACTION="UPLOAD" FILEFIELD="ul_path"
DESTINATION="C:\Documents\#dir#\"
NAMECONFLICT="OverWrite">
<CFSET ClientFilePath = "#clientDirectory#\#clientFile#">
</CFIF>
</CFIF>
</CFOUTPUT>
<br /><br />
Click on the Browse button to select the file to Upload:<br>
<input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""><br><br>
<input type="submit" name="upload_now" id="upload_now" value="Submit" style="height: 22px;">
<input type="button" name="clear" value="Clear" style="height: 22px;">
<br /><br /><br />
</form>
I hope this makes some sense - can anyone shed any light on getting this to work?
I am assuming that you didnt post the complete code because your #clientDirectory#/#clientFile# don't seem to have a source in your code above.
I put together a possible sample of what It may look like. I also moved your upload routine from the body of your code to the top for readability.
<CFIF IsDefined("form.upload_now")>
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<!--- assuming you need to lookup info from the database --->
<cfquery name="getThisLocation">
SELECT FolderID, FolderName, dir
FROM Locations
where foldername=#form.folderid#
</cfquery>
<CFFILE ACTION="UPLOAD" FILEFIELD="ul_path"
DESTINATION="C:\Documents\#getThisLocation.dir#\"
NAMECONFLICT="OverWrite">
<CFSET ClientFilePath = "#getThisLocation.clientDirectory#\##getThisLocation.clientFile#">
</CFIF>
</CFIF>
<cfquery name="getLocation">
SELECT *
FROM Locations
ORDER BY FolderName
</cfquery>
<form action="docuploads.cfm" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form">
<CFIF IsDefined("form.upload_now")>
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<P>FILE UPLOADED</P>
</CFIF>
</CFIF>
<select name="folderID">
<option value="">--- Select Folder ---</option>
<cfoutput query="getLocation">
<option value="#FolderName#"">#FolderName#</option>
</cfoutput>
</select>
<br /><br />
Click on the Browse button to select the file to Upload:<br>
<input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""><br><br>
<input type="submit" name="upload_now" id="upload_now" value="Submit" style="height: 22px;">
<input type="button" name="clear" value="Clear" style="height: 22px;">
<br /><br /><br />
</form>
I also added a snippet of code to let the user know that the file has been uploaded.
Please try this:
<CFIF IsDefined("form.upload_now")>
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<CFFILE ACTION="UPLOAD" FILEFIELD="#form.ul_path#"
DESTINATION="C:\Documents\#dir#\"
NAMECONFLICT="OverWrite">
<CFSET ClientFilePath = "#clientDirectory#\#clientFile#">
</CFIF>
<cfoutput>file uploaded successfully</cfoutput>
</CFIF>
<cfquery name="getLocation">
SELECT *
FROM Locations
ORDER BY FolderName
</cfquery>
<form action="docuploads.cfm" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form">
<select name="folderID">
<option value="">--- Select Folder ---</option>
<cfoutput query="getLocation">
<option value="#FolderName#"">#FolderName#</option>
</cfoutput>
</select>
<br /><br />
Click on the Browse button to select the file to Upload:<br>
<input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""><br><br>
<input type="submit" name="upload_now" id="upload_now" value="Submit" style="height: 22px;">
<input type="button" name="clear" value="Clear" style="height: 22px;">
<br /><br /><br />
I have a cfquery that is using some of FORM fields in the WHERE clause. My first problem is that every time I access my webpage the cfquery code appears on the top of the page. Where should I put the query within the .cfm form and access some of the fields within the form? My second problem is I'm not sure that the WHERE clause is recognizing the values for the fields. Can you help me please?
Here is the way my code is set up:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" type="text/javascript">
function addRow() {
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
var iteration = lastRow - 3;
var row = tbl.insertRow(lastRow);
........... etcetra.......
}
</script>
</head>
<body lang=EN-US style='tab-interval:.5in'>
<div class=Section1>
<cfparam name="awardTotals" default="0" />
<cfparam name="search_award.GrandTotal" default="0" />
<cfif isDefined("form.Finalize")>
<cfquery name="search_award" datasource="Test">
SELECT g.Code1 + g.Code2 + g.Code3 + g.Code4 AS GrandTotal
FROM Codes g
WHERE g.CodeNumber = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.CodeNum#">
AND g.TestYear = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.TestYear#">
AND g.SelType = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SelType#">
AND g.Jurisdiction = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SelJuris#">
</cfquery>
<cfif not search_award.GrandTotal is FundingTotals>
<script type="text/javascript">
alert('The totals do not match.');
return false;
</script>
<cfelse>
<script type="text/javascript">
alert('The totals match.');
return true;
</script>
</cfif>
</cfif>
<p class=MsoNormal align=center style='text-align:center'><
<cfoutput>
<form name="thisform" action="FormData.cfm" method="post">
<p class=MsoNormal align=left style='text-align:left'>
<input type="hidden" id="totalFields" name="totalFields" value="0">
<input type="text" id="awardTotals" name="#search_award.GrantTotal#" value="0">
<table width="1177" border="1" id="tblSample">
<tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes'>
<th height="10"bgcolor="##cccccc" colspan="10"><h3>Jurisdiction:
<select name="SelJuris" id="SelJuris">
<option value = "0">---Jurisdictions---</option>
<option value = "1">Allegany County</option>
<option value = "2">Anne Arundel County</option>
<option value = "3">Baltimore County</option>
<option value = "4">Calvert County</option>
<option value = "5">Caroline County</option>
</select>
<input name="CodeNum" id="CodeNum" type="text" size="20">
<input name="TestYear" id="TestYear" type="text" size="20">
<input name="SelType" id="SelType" type="text" size="20">
</th>
</tr>
</table>
<input type="Submit" name="Submit Form" value="Submit Form" onClick="">
<input type="Button" name="Finalize" value="Finalize" onClick="">
</form>
</body>
</cfoutput>
</html>
(Update from comments)
Right now I'm getting a message that Element CODENUM is undefined in FORM
You want this sort of logic. If the form has been submitted, do something with it. In your case, it would be like this:
<cfif structkeyexists(form, "codenum")>
query, process, display, etc
<cfif>
rest of page
Also, you want to use query parameters for a variety of reasons. So this:
g.CodeNumber = '#form.CodeNum#'
becomes this:
g.CodeNumber = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.CodeNum#">
unless it's a number in which case you change the datatype.
You need add a condition around your cfquery. Also update the name of your submit button without spaces
<input type="Submit" name="SubmitForm" value="Submit Form" onClick="">
<cfif isDefined("form.SubmitForm")>
<cfquery name="search_award" datasource="TrenaTest">
SELECT g.Code1 + g.Code2 + g.Code3 + g.Code4 AS GrandTotal
FROM Codes g
WHERE g.CodeNumber = '#form.CodeNum#'
AND g.TestYear = '#form.TestYear#'
AND g.SelType = '#form.SelType#'
AND g.JurisdictionID = '#form.SelJuris#'
</cfquery>
</cfif>
Please note that in all the examples, a standard html form tag is being used, but the condition for the query is defined in the Coldfusion form scope. I believe you would need to convert the <form> to <cfform> and <input> to <cfinput> like:
...........
<cfinput type="Submit" name="SubmitForm" value="Submit Form" onClick="">
</cfform>
<cfif isdefined('form.submit')>
.............