House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Anyone see anything wrong with this code?

  << Previous Post |  RSS |  Tree View |  Sort Latest First |  Subscribe to this Group Next >> 

Anyone see anything wrong with this code?

Hi, all... Rick Faircloth 05/01/2012 12:57 PM
The problem seems to be the loopCounter  and the imagenumberindex on Brian Thornton 05/01/2012 01:00 PM
»>>I can't give any clues on error messages, because this Claude_Schnéegans 05/01/2012 01:13 PM
Hi, Brian, and thanks for the feedback... Rick Faircloth 05/01/2012 01:45 PM
Looks like a good solution for getting some error clues Rick Faircloth 05/01/2012 01:48 PM
You are refrencing as 1 and need to refrence as the index. Brian Thornton 05/01/2012 02:07 PM
Do you mean that I should use the "imageNumber" index variable Rick Faircloth 05/01/2012 02:24 PM
You can always add some tracing or logging to the function and output it .jonah 05/01/2012 02:43 PM
Correct. There is a x of how many exist. Brian Thornton 05/01/2012 03:17 PM
Rick if there is an error being thrown then the log files are important Andrew Scott 05/01/2012 03:42 PM
>>I'll have to work on translating this into jQuery. Claude_Schnéegans 05/01/2012 03:55 PM
Thanks for the info, Andrew! Rick Faircloth 05/01/2012 04:37 PM
True, true... :o) Rick Faircloth 05/01/2012 04:38 PM
I think I understand what you're saying, Brian. Rick Faircloth 05/01/2012 04:45 PM
The other thing to Rick, is if you are able to duplicate it on your Andrew Scott 05/01/2012 10:58 PM

05/01/2012 12:57 PM
Author: Rick Faircloth Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350918 Hi, all... I've just moved onto a new server and it seems that ever since that time, I've had problems getting this code to work. The code has been tweaked a lot, here, there, and everywhere over the last several days trying to figure out why it won't work. I can't give any clues on error messages, because this is part of a cfc on the back end of an ajax call. No errors show up in firebug or elsewhere. The breakdown the method occurs where this code begins. Prior to this code, data for a properly listing is inserted into a MySQL database...no problem. And, I should say that the code works through line 20, where the images are first written to the temp-images directory. The problem is that no files are written to the final directory and no entries are made into the table for the photos. This code has been running on another server for the last couple of years. (Plus the tweaks!) I had the temp directory outside the web root, but brought it inside the web root thinking that might be the problem, but it didn't help. I broke out the individual functions of this code and ran them locally and everything checked out locally, but combined and on the server, no go... Thanks for any feedback! Rick <cfquery  name = "qGetLastInsertID"  datasource = "myDatasource">      select     LAST_INSERT_ID() as propertyID      from       rentalProperties              </cfquery>              <cfset loopCounter = 1> <cfloop index="imageNumber" from="1" to="100" step="1">      <cfset imageFileField = '#imageNumber#_propertyPhoto' />      <cfif (StructKeyExists(FORM, imageFileField) AND Len(FORM[imageFileField]))>                         <cffile  action       =  "upload"               filefield    =  "#imageFileField#"               destination  = "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images"               accept       =  "image/jpg, image/pjpg, image/jpeg, image/pjpeg, image/png"               nameConflict =  "makeUnique" />      <cfset    originalImageFileName = '#cffile.serverFileName#' />      <cfset    newImageFileName      = reReplace(#originalImageFileName#, [^a-zA-Z0-9_\-.], '', 'all') />      <cfset    originalImageExt      = '#cffile.serverFileExt#' />      <cfset    newFileNameComplete   = '#newImageFileName##originalImageExt#' />      <cfdirectory action      =  "list"                   directory  = "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images"                   name        =  "image_list"  />      <cfif image_list.recordCount gt 0  >           <cfloop query = "image_list">                <cfif name is '#newFileNameComplete#'  >                     <cffile  action       = "rename"                              source       = "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#newFileNameCompl ete#"                              destination  = "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#newImageFileName #_#loopCounter##originalImageExt#">                     <cfset  renamedNewFileNameComplete = '#newImageFileName#_#loopCounter##originalImageExt#'/>                <cfelse>                     <cfset  renamedNewFileNameComplete = '#newFileNameComplete#'  />                </cfif>                <cfif isImageFile('e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#rena medNewFileNameComplete#')  >                     <cfimage  action       =  "resize"                               width        =  "200"                               height       =  ""                               source       = "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#renamedNewFileNa meComplete#"                               destination   = "e:\inetpub\webroot\holtzmanRentals\user_images\photo200_#renamedNewFileName Complete#"                               overwrite    =  "true" />                     <cfset    photo200     = "photo200_#renamedNewFileNameComplete#">                     <cfimage  action       =  "resize"                               width        =  "75"                               height       =  "50"                               source       = "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#renamedNewFileNa meComplete#"                               destination  = "e:\inetpub\webroot\holtzmanRentals\user_images\photo75x50_#renamedNewFileNa meComplete#"                               overwrite    =  "true"  />                     <cfset    photo75x50   = "photo75x50_#renamedNewFileNameComplete#"  />                     <cfimage  action       =  "resize"                               width        =  "458"                               height       =  "306"                               source       = "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#renamedNewFileNa meComplete#"                               destination  = "e:\inetpub\webroot\holtzmanRentals\user_images\photo458x306_#renamedNewFile NameComplete#"                               overwrite    =  "true"  />                     <cfset    photo458x306 = "photo458x306_#renamedNewFileNameComplete#"  />                     <cffile   action       =  "delete"                               file         = "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#renamedNewFileNa meComplete#"  />                     <cfquery  name = "qInsertPhotos" datasource="myDatasource">                                              insert                               into       rentalPhotos                                                           ( propertyID, photo200, photo75x50, photo458x306, photoOrder )                                  values     ( <cfqueryparam  cfsqltype = "cf_sql_int"      value = "#qGetLastInsertID.propertyID#"  >,                                            <cfqueryparam  cfsqltype = "cf_sql_varchar"  value = "#photo200#" >,                                            <cfqueryparam  cfsqltype = "cf_sql_varchar"  value = "#photo75x50#" >,                                            <cfqueryparam  cfsqltype = "cf_sql_varchar"  value = "#photo458x306#" >,                                            <cfqueryparam  cfsqltype = "cf_sql_int"      value = "#loopCounter#" >                                          )                        </cfquery>                                </cfif> <!--- [ cfif isImageFile ] --->                 <cfset loopCounter = loopCounter + 1 />             </cfloop> <!--- [ imageList name ] --->         </cfif> <!--- [ imageList.recordCount gt 0 ] --->                  </cfif> <!--- [ if structKeyExists, imageFileField ] ---> </cfloop> <!--- [ image 1 to 100 ] ---> <cfset addPropertyStruct.STATUS = 'Success' />            <cfreturn addPropertyStruct  />
05/01/2012 01:00 PM
Author: Brian Thornton Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350919 The problem seems to be the loopCounter  and the imagenumberindex on my end. ----- Excess quoted text cut - see Original Post for more -----
05/01/2012 01:13 PM
Author: Claude_Schnéegans Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350921 »>>I can't give any clues on error messages, because this is part of a cfc on the back end of an ajax call. No errors show up in firebug or elsewhere. This is a problem with Ajax calls. If the template called by Ajax throws an error, the text returned by the CF server is not compatible with Ajax and it causes an Ajax error. This error will not help, what one is intersted in is the error in the CF error. I've developped my own Ajax call function, and in case of error, it will open a new window with the whole text returned in it. Generally, it is the error generated by CF. This one is for POST method, but I have the equivalent for GET: If there is anything wrong, the function calls displayError to displat the text actually received. function ajaxPOST (url, sendText)    {    var XMLHttp = null;      if (window.XMLHttpRequest)XMLHttp = new XMLHttpRequest();      // code for MSIE      else if (window.ActiveXObject)XMLHttp = new ActiveXObject("Microsoft.XMLHttp");    if(XMLHttp)      {      XMLHttp.open("POST", url, false);      XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");      XMLHttp.send(sendText);      if (XMLHttp.status == 200)return XMLHttp.responseText;      displayError("<H2>" + XMLHttp.statusText + "</H2><P>" + XMLHttp.responseText)      return null;      }      else return null;    } function displayError(text)      {      var errorWin = open ("","Error","scrollbars=yes,resizable,width=900,height=600");      errorWin.document.open();      errorWin.document.write(text);      errorWin.document.close();    errorWin.focus()      }
05/01/2012 01:45 PM
Author: Rick Faircloth Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350924 Hi, Brian, and thanks for the feedback... What, in particular, do you think is wrong with the loopCounter variable? I moved it over the last few days thinking that might be the problem. And, concerning the imagenumberindex... same question as above. And how were you able to test the code? Did you set up some file fields in a form and submit them to the cfc method? My client has been patient with this problem, but I may have to re-write this code as a plain-old, "submit the form to a .cfm processing page for the data, and repeat for the photos" solution.  I haven't been able to find the problem while using HTML, AJAX, IFrame, and a CFC method. Usually, I can troubleshoot this setup without any problem. But I just can't seem to get a handle on this one. Rick The problem seems to be the loopCounter  and the imagenumberindex on my end. ----- Excess quoted text cut - see Original Post for more ----- "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#newFileNameCompl > ete#" >                             destination  = > "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#newImageFileName ----- Excess quoted text cut - see Original Post for more ----- isImageFile('e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#rena ----- Excess quoted text cut - see Original Post for more ----- "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#renamedNewFileNa > meComplete#" >                              destination        = > "e:\inetpub\webroot\holtzmanRentals\user_images\photo200_#renamedNewFileName ----- Excess quoted text cut - see Original Post for more ----- "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#renamedNewFileNa > meComplete#" >                              destination  = > "e:\inetpub\webroot\holtzmanRentals\user_images\photo75x50_#renamedNewFileNa ----- Excess quoted text cut - see Original Post for more ----- "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#renamedNewFileNa > meComplete#" >                              destination  = > "e:\inetpub\webroot\holtzmanRentals\user_images\photo458x306_#renamedNewFile ----- Excess quoted text cut - see Original Post for more ----- "e:\inetpub\webroot\holtzmanRentalsSiteManager\temp-images\#renamedNewFileNa ----- Excess quoted text cut - see Original Post for more ----- photo75x50, ----- Excess quoted text cut - see Original Post for more -----
05/01/2012 01:48 PM
Author: Rick Faircloth Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350925 Looks like a good solution for getting some error clues back from AJAX calls. I'll have to work on translating this into jQuery. Usually, I can find some CF error code in the iFrame used to process the file uploads, but nothing is appearing there, or in the JSON reply. Thanks for the tip! Rick [mailto:=?ISO-8859-1?Q?Claude_Schn=E9egans <schneegans@interneti=71?= =?ISO-8859-1?Q?ue.com=3E?=] Sent: Tuesday, May 01, 2012 1:13 PM To: cf-talk Subject: Re: Anyone see anything wrong with this code? »>>I can't give any clues on error messages, because this is part of a cfc on the back end of an ajax call. No errors show up in firebug or elsewhere. This is a problem with Ajax calls. If the template called by Ajax throws an error, the text returned by the CF server is not compatible with Ajax and it causes an Ajax error. This error will not help, what one is intersted in is the error in the CF error. I've developped my own Ajax call function, and in case of error, it will open a new window with the whole text returned in it. Generally, it is the error generated by CF. This one is for POST method, but I have the equivalent for GET: If there is anything wrong, the function calls displayError to displat the text actually received. function ajaxPOST (url, sendText)    {    var XMLHttp = null;      if (window.XMLHttpRequest)XMLHttp = new XMLHttpRequest();      // code for MSIE      else if (window.ActiveXObject)XMLHttp = new ActiveXObject("Microsoft.XMLHttp");    if(XMLHttp)      {      XMLHttp.open("POST", url, false);      XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");      XMLHttp.send(sendText);      if (XMLHttp.status == 200)return XMLHttp.responseText;      displayError("<H2>" + XMLHttp.statusText + "</H2><P>" + XMLHttp.responseText)      return null;      }      else return null;    } function displayError(text)      {      var errorWin = open ("","Error","scrollbars=yes,resizable,width=900,height=600");      errorWin.document.open();      errorWin.document.write(text);      errorWin.document.close();    errorWin.focus()      }
05/01/2012 02:07 PM
Author: Brian Thornton Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350926 You are refrencing as 1 and need to refrence as the index. ----- Excess quoted text cut - see Original Post for more -----
05/01/2012 02:24 PM
Author: Rick Faircloth Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350928 Do you mean that I should use the "imageNumber" index variable in place of the loopCounter variable? You are refrencing as 1 and need to refrence as the index. ----- Excess quoted text cut - see Original Post for more ----- CF ----- Excess quoted text cut - see Original Post for more -----
05/01/2012 02:43 PM
Author: .jonah Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350930 You can always add some tracing or logging to the function and output it to a file to study offline. You can also create a dummy html form and post it to the cfc instead of using ajax. that way you can see whatever errors and debugging come back. On 5/1/12 10:48 AM, Rick Faircloth wrote: ----- Excess quoted text cut - see Original Post for more -----
05/01/2012 03:17 PM
Author: Brian Thornton Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350932 Correct. There is a x of how many exist. ----- Excess quoted text cut - see Original Post for more -----
05/01/2012 03:42 PM
Author: Andrew Scott Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350934 Rick if there is an error being thrown then the log files are important here. An other thing to note is that it might pay to look at something like this. http://www.andyscott.id.au/2011/8/27/ColdFusion-and-Remote-Calls-and-notifying-the-caller-of-the-problem This is how I handle all Ajax calls, so that the client can then decide on what to do if it succeeds or fails. So in the case of a failure you could then display a human readable error or notification that could be reported to you, but the biggest part of this entire equation will be error logging using the <cflog /> or even emails for sending important information if need be. -- Regards, Andrew Scott WebSite: http://www.andyscott.id.au/ Google+: http://plus.google.com/108193156965451149543 On Wed, May 2, 2012 at 3:48 AM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more -----
05/01/2012 03:55 PM
Author: Claude_Schnéegans Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350935 >>I'll have to work on translating this into jQuery. ... or simply use my function it as is. It has been working fine for years, long before jQuery was on the market.
05/01/2012 04:37 PM
Author: Rick Faircloth Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350937 Thanks for the info, Andrew! Rick if there is an error being thrown then the log files are important here. An other thing to note is that it might pay to look at something like this. http://www.andyscott.id.au/2011/8/27/ColdFusion-and-Remote-Calls-and-notifyi ng-the-caller-of-the-problem This is how I handle all Ajax calls, so that the client can then decide on what to do if it succeeds or fails. So in the case of a failure you could then display a human readable error or notification that could be reported to you, but the biggest part of this entire equation will be error logging using the <cflog /> or even emails for sending important information if need be. -- Regards, Andrew Scott WebSite: http://www.andyscott.id.au/ Google+: http://plus.google.com/108193156965451149543 On Wed, May 2, 2012 at 3:48 AM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- CF ----- Excess quoted text cut - see Original Post for more -----
05/01/2012 04:38 PM
Author: Rick Faircloth Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350938 True, true... :o) [mailto:=?ISO-8859-1?Q?Claude_Schn=E9egans <schneegans@interneti=71?= =?ISO-8859-1?Q?ue.com=3E?=] Sent: Tuesday, May 01, 2012 3:55 PM To: cf-talk Subject: Re: Anyone see anything wrong with this code? >>I'll have to work on translating this into jQuery. ... or simply use my function it as is. It has been working fine for years, long before jQuery was on the market.
05/01/2012 04:45 PM
Author: Rick Faircloth Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350940 I think I understand what you're saying, Brian. I understand the index value, but I'm using a loopCounter (a bad choice of variable name, since it's not an actual count of loops) to be able to add a number to a photo filename that will make it distinct from another photo with the same name. (At least for the ones uploaded...come to think of it, I need to make the photo name distinct from all photos in the "user-images" directory, not just when compared to other photos being uploaded for a specific property.  I'll need to look into that. Anyway, the loopCounter variable isn't actually serving the function of appending a numeric value equal to the number of loops through the code. Am I understanding you correctly? Rick Correct. There is a x of how many exist. ----- Excess quoted text cut - see Original Post for more ----- error ----- Excess quoted text cut - see Original Post for more ----- the >> error generated by CF. >> This one is for POST method, but I have the equivalent for GET: >> If there is anything wrong, the function calls displayError to displat the ----- Excess quoted text cut - see Original Post for more -----
05/01/2012 10:58 PM
Author: Andrew Scott Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:63886#350947 The other thing to Rick, is if you are able to duplicate it on your development server, you might want to look into line debugging to help narrow it down. I swear by the line debugger to find hard to find problems like this. -- Regards, Andrew Scott WebSite: http://www.andyscott.id.au/ Google+: http://plus.google.com/108193156965451149543 On Wed, May 2, 2012 at 6:36 AM, Rick Faircloth <Rick@whitestonemedia.com>wrote: > > Thanks for the info, Andrew! > > >
<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 25, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference