7 Replies - 2380 Views - Last Post: 09 December 2010 - 07:12 PM Rate Topic: -----

#1 zej  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-December 10

Cannot upload multiple files in firefox

Posted 01 December 2010 - 12:42 AM

Hello there! I'm a newbie in Coldfusion. Need some help regarding multiple uploads using cffile. Here is my code:

<cfif structKeyExists(FORM,"counter")>
	<cfparam name="FORM.counter" default="0">
	<cfloop index="j" from="1" to="#form.counter#" step="1">
		<cfif structKeyExists(FORM,"fileUp"&j)>
							
			<cffile action="upload"
			destination="#ab_path#\attachments"
			nameconflict="makeunique"
			filefield="form.fileUp#j#">
			<cfquery datasource="remittance">
				insert into jFiles(jTopicID,jDateSaved,jClientFile, jServerFile, jServerDirectory, jContentType, jContentSubType)
				values(#getTopicID.jTopicID#,getdate(),'#cffile.clientFile#','#cffile.serverFile#','#cffile.serverDirectory#','#cffile.contentType#', '#cffile.contentSubType#')
			</cfquery>
							
		</cfif>
	</cfloop>
</cfif>



When I use Internet Explorer, it works perfectly. The problem is in Firefox, I can only upload the first file. The rest of the files are not uploaded nor saved in the database. Why is it not working in Firefox? Am I missing something? Thanks for the help.

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot upload multiple files in firefox

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1914
  • View blog
  • Posts: 3,448
  • Joined: 13-January 08

Re: Cannot upload multiple files in firefox

Posted 01 December 2010 - 06:51 AM

Welcome to D.I.C. zej!

So, runs okay in IE, only once in FF. You said you're a CF newb but that's not newb code you have there...did you write that? Just curious.

In any event, the skill you're looking for is called "debugging" and it's not always invoked when there's an error. In your case, the code is working correctly (in that it's not throwing an error) but it's not doing what is expected and the difference appears to be based on the browser being used. Those two situations (runs without error but doesn't run as expected) leads me to look at your CFLOOP. I'd guess that since you're looping over form.counter that, for FF, form.counter is a 1.

One tag you're going to want to discover (and which will become one of your CF BFF's) is CFDUMP. I'd suggest that prior to that entire block of code you posted, you try this:
<cfdump var="#form#"><cfabort>

What that will do for you is it will literally dump the entire form scope (presumably from a previously submitted form page) to your browser screen and then halt processing. What you're looking for in there is the form variable entitled "counter" and it's attendant value. I'd bet you'll find that in FF it'll be a 1 and that in IE it'll be something more than 1.

If that is what you discover then your file upload page is working fine and the issue likely resides on the page that contains the form that was submitted and how the counter form field was populated.

If you need more assistance, post back here and I'm sure we can help you along.

Good luck!
Was This Post Helpful? 2
  • +
  • -

#3 zej  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-December 10

Re: Cannot upload multiple files in firefox

Posted 01 December 2010 - 08:07 PM

Hi Craig! Thanks for the reply. I just started using Coldfusion five months ago. I never had formal training here, so I just relied on forums and tutorials. As for the code, I also got ideas from what I saw on forums and applied it to my code. My original code was:

<cfloop index="j" from="1" to="#counter#" step="1">
   <cfset filename1="fileUp" & #j#>
   <cfif isDefined("filename1")>
      <cfif filename1 neq "">
         <cffile action="upload" destination="#ab_path#\attachments" nameconflict="makeunique" filefield="#filename1#">
	 <cfquery datasource="#source#">				insert into jFiles(jTopicID,jDateSaved,jClientFile, jServerFile, jServerDirectory, jContentType, jContentSubType)			values(#getTopicID.jTopicID#,getdate(),'#cffile.clientFile#','#cffile.serverFile#','#cffile.serverDirectory#','#cffile.contentType#', '#cffile.contentSubType#')
	 </cfquery>
      </cfif>
   </cfif>
</cfloop>



In IE, this also works. But in FF, I get an error: The form field fileUp2 did not contain a file. I thought this block of code has something wrong, so I revised it and came up with the code I previously posted. Still, it didn't work well in FF.

Thanks for your help. I tried including cfdump and here are the results. In IE, variable counter has 2 as its value, and fileUp1 and fileUp2 both have values. While in FF, counter is equal to 2. But the weird thing, only fileUp1 has value. There was no fileUp2 that was passed in FF. Now I see that it really did not contain a file. How come the field fileUp2 wasn't passed? Here is a part of my form code:

<input name="button" type="button" value="Attach More" onclick="addThisRow()"/>
<script type="text/javascript">
 function addThisRow(){
  var table = document.getElementById('addTable');
  var ctr = eval(document.getElementById('counter').value) + 1;
  var row = table.insertRow(eval(table.rows.length)-3); 
  var cell1 = row.insertCell(0);
  document.getElementById('counter').value=eval(ctr);
  var nameOfFile='fileUp'+ctr;
  var newHTML='<span width="625" colspan="2" style="font-size:14px">Attach this File:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input size="75" type="file" name="'+nameOfFile+'"/></span>';
  cell1.innerHTML =newHTML;
}
</script>



Thanks again.
Was This Post Helpful? 0
  • +
  • -

#4 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1914
  • View blog
  • Posts: 3,448
  • Joined: 13-January 08

Re: Cannot upload multiple files in firefox

Posted 02 December 2010 - 07:07 AM

Ah! I see. What you're actually running into then is a Javascript issue. I was kind of suspicious about it being a CF issue because CF is handled server side and should work the same for all browsers. So, what you're doing there is dynamically building a form by adding a new input field for each time a user clicks the Attach More button, right?

I'm not as strong in Javascript as I am in CF but as in most things with development, there's almost always more than one way to skin a cat. Do you have a maximum number of files you'd be willing to allow a user to upload? If so, then perhaps you might consider building all those elements on the form page beforehand, give them a CSS display property of "none" to start and then use the Javascript function to change their display property to "block" or "inline" or whatever works. You'd end up submitting all of them but it's a relatively simple task to loop over the maximum number a user could send, evaluate each form element for a value and process it if a value exists. Once you hit one with no value you can CFBREAK out of the loop and continue processing.

If that's not the way you want to go (and really want to keep it the way it is and make it work for FF) I'd start troubleshooting the Javascript with a series of alert() dumps through the function. When you run the form in FF do the fields appear for the user to fill them in? Not to ask a stupid question but, are you sure you're putting them in the named/id'd form you have set up on that page? I see you're changing the HTML found within cell1 each time but it could be that cell1 may not be within the form tags and therefore possibly not being included with the form submission.

Can you post the entire form page? If so, some of us could copypasta it to our own servers and try it with FF (and I suspect Safari, Chrome, Opera, etc) and see what we get.
Was This Post Helpful? 1
  • +
  • -

#5 zej  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-December 10

Re: Cannot upload multiple files in firefox

Posted 06 December 2010 - 12:32 AM

I already put alert() dumps to check if I get the correct value of counter and the value of newHTML. It also works well, adding another row with an input field when I click Attach More button.

Maybe I'll try your suggestion that I will have a maximum number of file fields and loop through them. But what confuses me is why does it work in IE and not in FF. :)

Thanks Craig!
Was This Post Helpful? 0
  • +
  • -

#6 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1914
  • View blog
  • Posts: 3,448
  • Joined: 13-January 08

Re: Cannot upload multiple files in firefox

Posted 06 December 2010 - 07:02 AM

The more I think on this problem the more I'm thinking the issue lies with how you're adding the element. You're using an older (but supposedly capable) method for dynamically adding a form field. I did a little digging around and came up with this: addField demo() that uses a different (WC3 approved) process. Maybe you could try that and see what you get.

If all else fails, try asking this question in the Javascript forum. I'm certain they'd have an answer for you there.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#7 Guest_Mike*


Reputation:

Re: Cannot upload multiple files in firefox

Posted 09 December 2010 - 11:40 AM

zej,

I ran into a similar problem using <cffileupload worked great in IE but not in FF. The fix was to applend this to the action url. ?#urlEncodedFormat(session.urltoken)#"

I know this is not what your using but it may be the problem. If I remember correctly it was something about FF not maintaining the session.



<cffileupload url="/myproceeingpage.cfm?#urlEncodedFormat(session.urltoken)#"

Mike
Was This Post Helpful? 0

#8 zej  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-December 10

Re: Cannot upload multiple files in firefox

Posted 09 December 2010 - 07:12 PM

Thanks Craig and Mike! I'll definitely try your suggestions. I think addField demo() would be very helpful for me.

What I like about here in DIC is I can see the concern and willingness to help of the forum leaders and other members. Keep it up!

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1