I have a page that accepts user images, renames them and returns the new filename for further processing
<cffunction name="uploadfile" access="public" returntype="string">
<!--- TODO files should not be uploaded to web accesible directories - use #GetTempDirectory()# to use the temporary directory--->
<cfargument name="forma" type="struct" required="yes">
<cfargument name="db" type="string" required="yes">
<cfargument name="user_id" type="string" required="yes">
<cfparam name="new_filename" default="">
<cfset mediapath = expandpath('/ugc_images/images')>
<cfset thumbpath = expandpath('/ugc_images/images/thumbs')>
<cfif structKeyExists(forma,"fileUpload") and len(forma.fileUpload)>
<cffile action="upload" filefield="FileUpload" destination="#MediaPath#" nameconflict="makeunique" accept="image/jpeg,image/gif,image/png">
<!---<cfset serverfile.extension = right(file.serverFile, 3)> --->
<cfset new_filename= "#user_id#_#DateFormat(Now(), "mm-dd-yyyy")#.jpg">
<cffile action="rename" source="#MediaPath#/#file.serverFile#" destination="#MediaPath#/#new_filename#"/>
<cfimage source="#MediaPath#/#new_filename#" name="myImage">
<cfset ImageSetAntialiasing(myImage,"on")>
<cfif myImage.width gt 1000 or myImage.height gt 1000><cfset ImageScaleToFit(myImage,1000,1000)> </cfif>
<cfset ImageWrite(myImage,"#MediaPath#/#new_filename#")>
<cfif myImage.width gt 300 or myImage.height gt 300><cfset ImageScaleToFit(myImage,300,300)></cfif>
<cfset ImageWrite(myImage,"#thumbpath#/#new_filename#")>
</cfif>
<cfreturn "#new_filename#">
</cffunction><!---EO uploadfile--->
after calling that function (which does indeed upload and save the file and its thumbnail as intended, all coldfusion fucntions seem to hang. The webserver still serves plain text, but any coldfusion tag no matter how simple, timesout
for example, after the above I have this:
This text is served to the browser
<hr>
and this
<hr>
<cfoutput >but this times out</cfoutput>
and it never gets here
<hr>
It all works well on my local machine for development but on the remote (production) server it crashes. It's on a shared hosting so I have limited access to settings
any idea what's going on?
Related
Can anyone tell me what the problem is? I tried to run some .cfm files but it does not trigger any effect of cffunction except cfcomponent? Am I missing something? Can anyone explain to me?
<cfcomponent>
<cfset THIS.Name = "formdemo">
<cfset THIS.SessionManagement = true>
<cfset This.Sessiontimeout="#createtimespan(0,0,20,0)#">
<cfset This.applicationtimeout="#createtimespan(5,0,0,0)#">
--Entered cfcomponent--
<cffunction name="onApplicationStart" returnType="boolean" output="false">
--Entered Application Start--
<cfset application.portfolioUploadRoot = "ram:///portfoliouploads">
<cfif not directoryExists(application.portfolioUploadRoot)>
<cfdirectory action="create" directory="#application.portfolioUploadRoot#">
</cfif>
<cfreturn true>
</cffunction>
<cffunction name="onSessionStart" returnType="void" output="false">
--Entered Session Start--
<cfset session.myuploadroot = application.portfolioUploadRoot & "/" & replace(createUUID(), "-", "_", "all")>
<cfif not directoryExists(session.myuploadroot)>
<cfdirectory action="create" directory="#session.myuploadroot#">
</cfif>
</cffunction>
<cffunction name="onApplicationEnd" returnType="void" output="false">
--Entered Application End--
<cfargument name="applicationScope" required="true">
<cfif directoryExists(arguments.applicationScope.portfolioUploadRoot)>
<cfdirectory action="delete" recurse="true" directory="#arguments.applicationScope.portfolioUploadRoot#">
</cfif>
</cffunction>
<cffunction name="onSessionEnd" returnType="void" output="false">
--Entered Session End--
<cfargument name="sessionScope" type="struct" required="true">
<cfargument name="appScope" type="struct" required="false">
<cfif directoryExists(arguments.sessionScope.myuploadroot)>
<cfdirectory action="delete" recurse="true" directory="#arguments.sessionScope.myuploadroot#">
</cfif>
</cffunction>
</cfcomponent>
The result only shows "--Entered cfcomponent--" on the beginning of cfmpage.cfm.
cfmpage.cfm:
<cfparam name="form.textname" default="">
<cfparam name="form.textemail" default="">
<cfparam name="form.docattach" default="">
<cfif structKeyExists(form, "Submit")>
<cfset form.textname = trim(htmlEditFormat(form.textname))>
<cfset form.textemail = trim(htmlEditFormat(form.textemail))>
<cflocation url="formcomplete.cfm" addToken="false">
</cfif>
<!DOCTYPE html>
<html>
<head>
...
</head>
<body>
<form method="post" enctype="multipart/form-data">
<cfoutput>
<input id="textname" name="textname" type="text" class="input-large" required="" value="#form.textname#">
<input id="textemail" name="textemail" type="text" class="input-large" required="" value="#form.textemail#">
</cfoutput>
</form>
</body>
</html>
It is doing as it should.
onApplicationStart -- Runs when ColdFusion receives the first request for a page in the application.
For this, to easily see this, you can try changing the name of the application, then
visit a page within.
onSessionStart -- Only run upon the first visit within the session. If you wait til after the
timeout and then come back, you'll see this. Changing the application name will should also
retrigger this.
onSessionEnd -- Run when the session ends. It will trigger after the timeout, it's used so that
you can clean up activity. For instance, if you're using something like Application.NumberOnline.
OnSessionEnd can substract one (where onSessionStart) can add one.
onApplicationEnd -- Runs when the application timeout occurs or the server is shutting down.
Neither of the latter two will ever show any text on screen because you can't see that event while visiting the page. You can however call them manually to trigger their effects. You can, however, log these actions however you choose. You may use cflog, for instance, in this fashion:
<cffunction name="onApplicationEnd">
<cfargument name="ApplicationScope" required=true/>
<cflog file="#This.Name#" type="Information"
text="Application #Arguments.ApplicationScope.applicationname# Ended" >
</cffunction>
In other words:
<cfscript>
ap = createObject("component","Application");
ap.onSessionEnd(session,application);
</cfscript>
Will display the text because it is firing the event.
Finally, if you're wanting something to happen on each page, onRequestStart and onRequestEnd or onRequest are great options. OnRequest is a method that wraps around the page, so you can do header and footer actions in the same request, but you must explicitly include the file, wheras onRequestStart / onRequestEnd execute at the start and end of the request.
The order of action methods invoked is
onApplicationStart (runs on first application activity)
onSessionStart (runs on first session activity)
onRequestStart
onRequest
onRequestEnd
Lastly, functions don't fire unless they're called. This applies to functions you write yourself as well.
<cfscript>
function foo() {
writeoutput("bar");
}
</cfscript>
Won't do anything until you actually try something like <cfoutput>#foo()#</cfoutput>.
In the case of "default functions", these are just special functions/methods that CF calls at certain points if they're present.
I know this has been asked, but I cannot seem to find the solution that works.
I have a CFM page that uses the following to pass data to a CFC
<cfinvoke
component="common.cfcs.geotrails"
method="UpdateGeoTrail">
<cfinvokeargument name="title" value="#form.title#"/>
<cfinvokeargument name="Description_short" value="#form.Description_short#"/>
<cfinvokeargument name="Description" value="#form.description#"/>
<cfinvokeargument name="GTID" value="#form.gtid#"/>
<cfinvokeargument name="CatID" value="#form.catid#"/>
<cfif structKeyExists(form,"fileUpload") and len(form.fileUpload)>
<cfinvokeargument name="fileUpload" value="#form.fileUpload#"/>
</cfif>
</cfinvoke>
In the CFC that receives the data, I followed the direction at the Adobe Cookbook
<cffunction name="UpdateGeoTrail" access="public" returntype="void">
<cfargument name="title" type="string" required="yes">
<cfargument name="Description_short" type="string" required="yes">
<cfargument name="Description" type="string" required="yes">
<cfargument name="GTID" type="numeric" required="yes">
<cfargument name="CatID" type="numeric" required="yes">
<cfargument name="fileUpload" type="string" required="no">
<!--- IF THE IMAGE HAS BEEN UPLOADED --->
<!--- set the full path to the images folder --->
<cfif isdefined("arguments.fileUpload") AND len(arguments.fileUpload)>
<cfset tempmediapath = "#expandPath('/')#media/gtimages/temp/">
<cfset mediapath = "#expandPath('/')#media/gtimages/">
<cfset var cffile = "">
<cffile action="upload"
filefield="#ARGUMENTS.fileUpload#"
destination="#TempMediaPath#"
nameconflict="makeunique">
...
But I still get the dreaded error message...
"The form field /data/disk01/opt/coldfusion9/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp/neotmp5003883285207133802.tmp did not contain a file."
If I follow the directions at StackExchange
( CFFILE - Uploading a file using a component )
<cffile action="upload"
filefield="fileUpload"
destination="#TempMediaPath#"
nameconflict="makeunique">
It passes without error, but a <CFDUMP> shows: [empty string].
What am I missing.
Thanks.
Phil
I know it isn't part of your cfc but did you make sure that the form has the enctype set?
<cfform action="/upload.cfm" enctype="multipart/form-data">
By removing the cffile scope, I was able to get it to work.
I have a code below
<cffunction name="DeleteRecord">
<cfargument name="myFusebox" />
<cfargument name="event" />
<cfset event.xfa("ShowForm", "app.ShowForm") />
<cfset event.xfa("AddNew", "app.AddNew") />
<cfset event.xfa("EditRecord", "app.EditRecord") />
<cfset event.xfa("DeleteRecord", "app.DeleteRecord") />
<cfset event.xfa("UpdateRecord", "app.UpdateRecord") />
<cfset DeleteForecastRecord = application.report.ForecastRecordDelete(event.getValue("id"))/>
<cflocation url="#myFusebox.getMyself()##event.xfa('manageforecastreport')#" addtoken="false" />
</cffunction>
and in my cfc file below
<!--- ::::: Forecast Record Show ::::: --->
<cffunction name="ForecastRecordShow" returntype="query" access="public" output="true" hint="Add Forecast Record">
<cfargument name="ForecastID" type="any" default="">
<cfquery name="qryGetForcastRecord" datasource="#variables.dsn#">
SELECT * FROM tbl_forecast
WHERE ForecastID = <cfqueryparam cfsqltype="cf_sql_integer" value="#trim(arguments.ForecastID)#">
</cfquery>
<cfreturn qryGetForcastRecord>
</cffunction>
i have an error
Parsed file 'app.deleterecord.cfm' changed or did not exist
Request failed with exception 'Application' (The method ForecastRecordDelete was not found in component C:\Websites\LiquidMetalWheel.com\DiscountTire_dev\model\report.cfc.)
The method ForecastRecordDelete was not found in component C:\Websites\mysite.com\model\report.cfc.
Please help me about what can i do to solve this error
Make sure the "mode" is set to dev and not to prod (prod I think). When set to prod it will assume the file in the parsed directory is the correct one. When set to dev it "reparses" all your fuses with each request.
The "mode" setting is buried in your fusebox setttings - check the fbx_settings.cfm file. I'm doing this from memory so I might be wrong about the name of the setting (maybe appsettingStyle or something like that).
I was wondering if there is any strings centralization in ColdFusion similar to Android strings.xml file.
So, that my code remains intact if i want to do any changes in string
ColdFusion is a programming language, not a user interface framework.
There is nothing like Android's string resource management built into ColdFusion, but it would be very easy to implement that yourself.
resources/strings.xml:
<!-- keep as a structure with unique element names -->
<strings>
<heading>This is a test.</heading>
<greetings>
<hello>Hello World!</hello>
<bye>Goodbye World!</bye>
</greetings>
</strings>
ColdFusion utility function (for example in a CFC component util.cfc):
<cffunction name="ReadResouceXml" returntype="struct" access="public" output="no">
<cfargument name="path" type="string" required="yes">
<!--- internal use argument --->
<cfargument name="xmlDoc" type="xml" required="no">
<cfset var xmlElem = "">
<cfset var output = StructNew()>
<!--- read XML file from disk --->
<cfif not StructKeyExists(arguments, "xmlDoc")>
<cffile action="read" file="#ExpandPath(path)#" variable="xmlDoc" charset="UTF-8">
<cfset xmlDoc = XmlParse(xmlDoc).XmlRoot>
</cfif>
<!--- recursively convert XML to a CF struct --->
<cfloop index="i" from="1" to="#ArrayLen(xmlDoc.XmlChildren)#">
<cfset xmlElem = xmlDoc.XmlChildren[i]>
<cfif ArrayLen(xmlElem.XmlChildren) gt 0>
<cfset output[xmlElem.XmlName] = ReadResouceXml("", xmlElem)>
<cfelse>
<cfset output[xmlElem.XmlName] = xmlElem.XmlText>
</cfif>
</cfloop>
<cfreturn output>
</cffunction>
Coldfusion usage:
<cfobject type="component" name="util" component="util">
<cfset strings = util.ReadResouceXml("resources/strings.xml")>
<cfoutput>
<h1>#strings.heading#</h1>
#strings.greetings.hello# - #strings.greetings.bye#
</cfoutput>
I have this add user form, it also doubles as a edit user form by querying the data and setting the value="#query.xvalue#". If the user exists (eg, you're editing a user, it loads in the users data from the database. When doing this on the <cffile field it does not load in the data, then when the insert goes to insert data it overrights the database values with a blank string (If a user does not input a new file). How do I avoid this?
Code:
Form:
<br/>Digital Copy<br/>
<!--- If null, set a default if not, set the default to database default --->
<cfif len(Trim(certificationsList.cprAdultImage)) EQ 0>
<cfinput type="file" required="no" name="cprAdultImage" value="" >
<cfelse>
File Exists: <cfoutput>View File</cfoutput>
<cfinput type="file" required="no" name="cprAdultImage" value="#certificationsList.cprAdultImage#">
</cfif>
Form Processor:
<!--- Has a file been specificed? --->
<cfif not len(Trim(form.cprAdultImage)) EQ 0>
<cffile action="upload" filefield="cprAdultImage" destination="#destination#" nameConflict="makeUnique">
<cfinvokeargument name="cprAdultImage" value="#pathOfFile##cffile.serverFile#">
<cfelse>
<cfinvokeargument name="cprAdultImage" value="">
</cfif>
CFC
ARGS:
<cfargument name="cprAdultExp" required="NO">
<cfargument name="cprAdultCompany" type="string" required="no">
<cfargument name="cprAdultImage" type="string" required="no">
<cfargument name="cprAdultOnFile" type="boolean" required="no">
Query:
UPDATE mod_StudentCertifications
SET
cprAdultExp='#DateFormat(ARGUMENTS.cprAdultExp, "mm/dd/yyyy")#',
cprAdultCompany='#Trim(ARGUMENTS.cprAdultCompany)#',
cprAdultImage='#Trim(ARGUMENTS.cprAdultImage)#',
cprAdultOnFile='#Trim(ARGUMENTS.cprAdultOnFile)#'
INSERT INTO
mod_StudentCertifications(
cprAdultExp,
cprAdultcompany,
cprAdultImage,
cprAdultOnFile
<cfif not
len(Trim(form.cprAdultImage)) EQ 0>
That is actually doing the reverse of what you want. I believe what you are trying to say is:
<!--- if the length is greater than 0, assume a file was uploaded --->
<cfif len(Trim(form.cprAdultImage)) GT 0>
file is not empty. do the upload ...
<cfinvokeargument name="cprAdultImage" value="#pathOfFile##cffile.serverFile#">
<cfelse>
<cfinvokeargument name="cprAdultImage" value="">
</cfif>
Edit
As an aside, .. since all of your arguments are optional, the code feels a bit awkward.
<cfinput type="file" required="no" name="cprAdultImage" value="#certificationsList.cprAdultImage#">,
You cannot really preset the file control "value" (browser security restrictions). Since a user can upload a file in both cases, just provide an input and display the "view" link only if a previous image exists.
<cfif len(Trim(certificationsList.cprAdultImage))>
File Exists:
<cfoutput>View File</cfoutput>
</cfif>
<cfinput type="file" required="no" name="cprAdultImage">
cprAdultImage='#Trim(ARGUMENTS.cprAdultImage)#',
The UPDATE logic looks a bit off as well. If a file was not supplied, you will end up overwriting the existing image with an empty string. To avoid that, only update that field if a new file was supplied (ie non-empty)
Form processing:
<cfif len(Trim(form.cprAdultImage)) GT 0>
<cffile action="upload" filefield="cprAdultImage" destination="#destination#" nameConflict="makeUnique">
<cfinvokeargument name="cprAdultImage" value="#pathOfFile##cffile.serverFile#">
</cfif>
CFC ARGS:
<!--- if values are always used in queries, should be required=true --->
<cfargument name="cprAdultExp" required="yes">
<cfargument name="cprAdultCompany" type="string" required="yes">
<cfargument name="cprAdultOnFile" type="boolean" required="yes">
<cfargument name="cprAdultImage" type="string" default="">
Query
UPDATE mod_StudentCertifications
SET
cprAdultExp='#DateFormat(ARGUMENTS.cprAdultExp, "mm/dd/yyyy")#',
cprAdultCompany='#Trim(ARGUMENTS.cprAdultCompany)#',
<!--- only overwrite the value if a new file was supplied --->
<cfif len(trim(ARGUMENTS.cprAdultImage))>
cprAdultImage='#Trim(ARGUMENTS.cprAdultImage)#',
</cfif>
cprAdultOnFile='#Trim(ARGUMENTS.cprAdultOnFile)#'
WHERE ....
And do not forget cleanup. Remove any old files...