我正在尝试使用Datediff函数计算总月数,天数和小时数所用的时间.这不可能吗?
DateDiff("d hh", datein, Now)
Run Code Online (Sandbox Code Playgroud)
我能做什么?
压缩文档时,我很难重命名文件.在下面,我正在尝试从文档中获取字符串,替换并保存为具有UUID文件名的文档.我希望将文件的名称更改为压缩文件时可读的内容.我该怎么做?
<cfset rtf = FileRead(filepathofdocument) />
<cfset rtf = Replace(rtf,"%newProdYN%",session.input.inputtext) />
<cfset rtf = Replace(rtf,"%ration%",session.input.inputtext2) />
<cfset cfdest = "#GetDirectoryFromPath(session.input.storage.destination)#/#CreateUUID()#.doc" />
<cffile action = "write"
file = "#cfdest#"
output = "#rtf#">
<cfzip action="zip" file="#getTempDirectory()#/#CreateUUID()#.zip">
<cfzipparam source="#cfdest#" entrypath="document.doc" />
<!-- More file sources to zip... -->
</cfzip>
Run Code Online (Sandbox Code Playgroud)
cfzipparam
标签的输入路径似乎不起作用......
编辑:我实际上遵循了Ben Nadel博客的教程.http://www.bennadel.com/blog/795-learning-coldfusion-8-cfzip-part-ii-zipping-files-and-directories-with-cfzipparam.htm
我正在尝试为cffile上传做一个例外,以确保用户只上传xls相关文档或根本不上传.我有文件上传的问题.即使用户可能没有将任何内容附加到输入,表单仍将通过并假设表单字段b1b3formAttach定义.这是代码:
<cfif structKeyExists(form, "Submit")>
<cfif isDefined("Form.b1b3formAttach") >
<cffile action = "upload"
fileField = "b1b3formAttach"
destination = "#GetTempDirectory()#"
nameConflict = "overwrite">
<cfif isDefined("CFFILE.serverFile")>
<cfset session.slot = cffile.serverFile>
<cfelse>
<cfset form.storage = "">
</cfif>
</cfif>
<body>
<label class="control-label" for="b1b3formAttach">Attach the completed B1/B3 Form*</label></br>
<div class="controls">
<input id="b1b3formAttach" name="b1b3formAttach" class="input-file" type="file">
</div>
<div class="controls">
<button value="Submit" type="submit" id="Submit" name="Submit" class="btn btn-default">Submit</button>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
错误简述:
The form field b1b3formAttach did not contain a file.
The error occurred in C:/ColdFusion11/cfusion/wwwroot/wwwroot/form.cfm: line 21
19 : fileField …
Run Code Online (Sandbox Code Playgroud) 将文件上传到表单时遇到问题.基本上,我想检查会话是否包含先前在form.cfm中提交的文件.但是,遇到的问题:复杂对象类型无法转换为简单值.这些是我的代码:
form.cfm代码::
<cfif structKeyExists(form, "Submit")>
<cfif isDefined("Form.filecontent") AND evaluate("Form.filecontent") NEQ "" >
<cffile action = "upload"
fileField = "file"
destination = "#GetTempDirectory()#"
nameConflict = "overwrite">
<cfset form.storage = cffile>
<cfelse>
<cfset form.storage = "">
</cfif>
<cfset session.checkout.input = {
storage=form.storage
}>
<cflocation url="formcomplete.cfm" addToken="false">
</cfif>
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
<!-- Other Scripts or CSS... -->
</head>
<body>
<form method="post" enctype="multipart/form-data">
<cfoutput>
<input id="filecontent" name="filecontent" class="input-file" type="file" accept="application/vnd.ms-excel">
</cfoutput>
<button …
Run Code Online (Sandbox Code Playgroud) 我找不到一个简单的教程来帮助我完成这项任务.基本上我需要分配单选按钮的值并通过会话将其传递给下一页.这是我的单选按钮输入代码.
<input type="radio" name="statReqYN" id="statReqYN-0" value="Yes" checked="checked"> Yes
<input type="radio" name="statReqYN" id="statReqYN-1" value="No"> No
Run Code Online (Sandbox Code Playgroud)
之后,我将设置按钮的值:
<cfif isdefined("form.newProdYN") and form.newProdYN is "No">
<cfset form.newProdNY = "No">
</cfif>
Run Code Online (Sandbox Code Playgroud)
最后,我将通过提交按钮将其传递到同一会话的下一页:
<cfif not arrayLen(errors)>
<cfset session.checkout.input = {
newProdNY=form.newProdNY}>
<cflocation url="formcomplete.cfm" addToken="false">
</cfif>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在html中使用#session.checkout.input.newProdYN#获取值时,结果是未定义的.任何人都可以帮我解决这个问题吗?