<!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" lang="en" />
<script language="javascript" src="s_js/jquery.min.js"></script>
<script language="javascript" src="s_js/jquery.form.js"></script>
<script language="javascript">
$(document).ready(function() {
$('#submitImage').bind('click', function(){
$(".preview").html('');
$(".preview").html('<img src="images/loader.gif" alt="Uploading...."//>');
$("#cropimage").ajaxForm({
target: '.preview'
}).submit();
});
});
</script>
</head>
<body>
<table align="center" width="750" cellpadding="1" cellspacing="2" style="border:1px solid #F00">
<tr>
<td colspan="2">
<form id="cropimage" method="post" enctype="multipart/form-data" action='ajaximage.cfm'>
<table width="100%" align="center" cellpadding="2" cellspacing="0">
<tr><td align="left"><input type="file" name="uploadurlimage" style="border:1px solid #666;" id="uploadurlimage"/></td></tr>
<tr><td align="left"><input type="button" name="submitImage" id="submitImage" class="acb" value="Upload"></td></tr>
</table>
<br /><div class='preview'></div>
</form></td>
</tr>
</table>
</body>
</html>
<cfset validFormats = "image/*">
<cfif isDefined('uploadurlimage') AND uploadurlimage NEQ ''>
<cfset ifolder8 = "temp">
<cfset nifolder8 = ExpandPath("myfolder/#ifolder8#")>
<cfset TAB = Chr(9)>
<cfif NOT DirectoryExists(nifolder8)>
<cfdirectory action="create" directory="#nifolder8#" mode="777">
</cfif>
<cfset Path = nifolder8>
</cfif>
<cffile action="upload" filefield="uploadurlimage" accept="#validFormats#" destination="#Path#\" nameconflict="overwrite">
<cfset sFile = cffile.serverFile>
<cfimage action="resize" width="#form.isize#" height="" source="#Path#\#sFile#" destination="#Path#\#sFile#" overwrite="yes">
<cfimage action="write" source="#Path#\#sFile#" destination="#Path#\#sFile#" overwrite="true">
<cfoutput><img src="#Path#/#sFile#" /></cfoutput>
$(document).ready(function() {
$('#submitImage').bind('click', function(){
$(".preview").html(''); //This is the div we have defined where we will show the uploaded file
$(".preview").html('<img src="images/loader.gif" alt="Uploading...."//>'); // This is actually called to show the progress bar, if we do not want it, we can actually remove this thing
$("#cropimage").ajaxForm({
target: '.preview'
}).submit(); // cropimage is the name of the form from where we are doing an ajaxForm submission and it does this stuff at backend, we have used the target attribute to show the uploaded or any message in the preview div class, which will show us the result. and lastly we are just doing the submission, see that is a post request.
});
});
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)