Note that there are some explanatory texts on larger screens.

plurals
  1. POfile upload strange issue with size and extension
    primarykey
    data
    text
    <p>I am currently working on a script that will allow users to upload images, nothing too sophisticated just a few simple lines of code. Anyway, last night everything was working like a charm and now surprise surprise, strange things started happening out of the blue for who knows what reason. That said, it's important to note that I am asynchronously passing values using <strong>jQuery Form Plugin</strong> and that part has been working flawlessly hence I will not post that part of the code.</p> <p>here is the cfc component code:</p> <pre><code>&lt;cfcomponent output="false"&gt; &lt;cffunction name="test" access="remote" output="false"&gt; &lt;cfparam name="form.title" type="string" default=""&gt; &lt;cfparam name="form.File" type="string" default=""&gt; &lt;cfset add.Msg = ArrayNew(1)&gt; &lt;!---check if text is added and whether it contains more than 15 characters---&gt; &lt;cfif len (trim(form.title)) is 0&gt; &lt;cfset ArrayAppend(add.Msg,"plese enter some text")&gt; &lt;cfelseif len (trim(form.title)) lt 15&gt; &lt;cfset ArrayAppend(add.Msg,"text should be at least 15 characters long")&gt; &lt;/cfif&gt; &lt;!---check if text contains special characters---&gt; &lt;!--additionally we can allow other characters--&gt; &lt;cfif refind ("[^A-Z a-z 0-9\\+]+", form.title) and len (trim(form.title)) gte 15&gt; &lt;cfset ArrayAppend(add.Msg,"your post can not conatin special characters")&gt; &lt;/cfif&gt; &lt;!---check to see if file has been submited---&gt; &lt;cfif len(form.File) is 0&gt; &lt;cfset ArrayAppend(add.Msg,"you haven't selected a file")&gt; &lt;/cfif&gt; &lt;!---if there are no errors try to upload file to temp---&gt; &lt;cfif ArrayLen (add.Msg) is 0&gt; &lt;cftry&gt; &lt;cffile action="upload" nameconflict="makeunique" destination="#GetTempDirectory()#" filefield="File"&gt; &lt;!---check file size---&gt; &lt;cfif (CFFILE.FileSize GT (100 * 1024))&gt; &lt;cfset ArrayAppend(add.Msg,"#CFFILE.FileSize#you can not upload files bigger than 1MB")&gt; &lt;!---try to delete the file---&gt; &lt;cftry&gt; &lt;cffile action="delete" file="#CFFILE.ServerDirectory#\#CFFILE.ServerFile#"&gt; &lt;cfcatch&gt; &lt;!--we dan catch an error , though it would crash the page--&gt; &lt;/cfcatch&gt; &lt;/cftry&gt; &lt;/cfif&gt; &lt;!---check file extension with aditional layer of protection for just in case---&gt; &lt;cfif not ListFindnoCase("jpg,jpeg,png,gif",CFFILE.ServerFileExt) or not isImageFile("#GetTempDirectory()##CFFILE.ServerFile#")&gt; &lt;cfset ArrayAppend(add.Msg,"#CFFILE.ServerFileExt#you can only upload jpg,png or gif images.")&gt; &lt;!---try to delete the file---&gt; &lt;cftry&gt; &lt;cffile action="delete" file="#CFFILE.ServerDirectory#\#CFFILE.ServerFile#"&gt; &lt;cfcatch&gt; &lt;!--again we can catch an error, though it would crash the page--&gt; &lt;/cfcatch&gt; &lt;/cftry&gt; &lt;/cfif&gt; &lt;cfcatch&gt; &lt;!--if there was an error we could log it, though that would crash the page--&gt; &lt;/cfcatch&gt; &lt;/cftry&gt; &lt;/cfif&gt; &lt;cfif ArrayLen (add.Msg) is 0&gt; &lt;cfset ArrayAppend(add.Msg,"#CFFILE.ServerFile# - yay! success")&gt; &lt;/cfif&gt; &lt;cfreturn serializeJSON(add.Msg)&gt; &lt;/cffunction&gt; </code></pre> <p></p> <p>as you can see it's a simple validation that should work and has worked as I mentioned last night. Now I am having issues with file size and file format validation. That said, whatever I try it returns that file is bigger that 1M and that it's not a correct type, even though I select 300kb file, jpg or png. as you can see i added #CFFILE.FileSize# and #CFFILE.ServerFileExt# to those to error msgs and file is there, it's less than 1MB in size and its correct type. So, WTF is going on here? I would really appreciate your help on this one, if you have any suggestions on how to fix this or how to improve my code.</p> <p><strong>EDIT</strong></p> <p>this is a testing client side code</p> <pre><code>$(document).ready(function(){ var options = { beforeSend: function() { /* something will go here */ }, uploadProgress: function(event, position, total, percentComplete) { /* maybe in here */ }, success: function(data) { /*test */ /*alert(data); return false;*/ }, complete: function(response) { /* test */ alert(response.responseText); return false; }, error: function(error) { /*alert('error'); return false;*/ } }; $("#JqAjaxForm").ajaxForm(options); }); </code></pre> <p>and form</p> <pre><code>&lt;form id="JqAjaxForm" action="cfc/tests.cfc?method=test" method="post" enctype="multipart/form-data"&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload