Copy link to clipboard
Copied
I have following code to use cffile upload a file.
I am able to upload the file from client machine to server machine.
The only thing is after upload file, browser refresh my screen using url string without paramer like
http://www.myserver.com/myapp.cfm
but my original url is
http://www.myserver.com/myapp.cfm?MyParam=1
because it change url string, the browser data refresh, no more their and it does not recognize paramter either that I can not save information to database.
I would like to know if there is any configuration need to do or coding to make file upload keep on the same screen or I have to have a separate form to upload the file.
Your help and information is great appreciated,
Regards,
Iccsi,
client side code:
<cfinput type="file" name="fleAttachment" id="filAttachment" >
<cfinput type="submit" name="btnAttach" id="btnAttache" value="upload">
<cfif isdefined("MyUpload")>
file uploaded!
</cfif>
here is server side code:
<cfif isdefined("btnAttach") and isdefined("fleAttachment")>
<cfset UploadFolder = "#application.upload_folder#" & "#form.MyParam#">
<cfif Not DirectoryExists("#UploadFolder#")>
<cfdirectory action = "create" directory="#UploadFolder#" />
</cfif>
<cffile action="UPLOAD" filefield="fleAttachment" destination="#UploadFolder#"
accept ="application/pdf, application/msword, application/vnd.ms-excel, text/plain" nameconflict="MAKEUNIQUE"
result="MyUpload">
here is Application.cfc to get application upload folder.
<cfset thisPath=ExpandPath("*.*")>
<cfset application.upload_folder=GetDirectoryFromPath(thisPath) & "Attachment\">
Copy link to clipboard
Copied
You're going to have to provide more details about the flow of your pages:
If you need to keep any URL parameters that are being passed around, you will have to attach them again and again to the URL of the form post.
<form action="myapp.cfm?#cgi.query_string#" method="post">
</form>
Otherwise, if you want to persist MyParam, you'll have to use a session variable to keep it persistent across pages. Or don't even bother passing it in the url, as soon as you have the value, set it as a session variable. You'll have to make sure you have sessionManagement=true in your application.cfc
<cfif structKeyExists( url, 'myParam' )>
<cfset session.myParam = url.myParam>
</cfif>
Copy link to clipboard
Copied
Thanks for the information and help,
My applicaiton.cfc has SessionMangement = True like following,
<cfset THIS.SessionManagement = true />
and I have set my param on the form like following
<CFIF structKeyExists(url, "MyParam")>
<CFSET form.MyParam= URL.Param>
</CFIF>
and form action like following
<cfform action="myform.cfm" method="post" name="frmMyForm" enctype="multipart/form-data">
I remember it was working before, but for some reason it does not work today when I test it,
Thanks again for helping and information,
Regards,
Iccsi,
Copy link to clipboard
Copied
Form and URL parameters do not persist from page request to page request unless you explcitly pass them in the URL or FORM.
<cfform action="myform.cfm" method="post" name="frmMyForm" enctype="multipart/form-data">
<!--- Pass the MyParam Value to the Next Page as a Form Variable --->
<input type="hidden" name="myParam" value="#url.MyParam#">
</cfform>
Copy link to clipboard
Copied
Thanks for the information and help,
Understand, I need set the param to the form, since cffile upload establish the form.
Thanks again for helping and information,
Regards,
Iccsi,