I have a problem getting Coldfusion 8 to display my image (#image_name#) in the following code. I am wondering if a second pair of eyes can see my problem. <cfloop query="getrecord"> <tr bgcolor="ffffff"> <td align=center valign=middle nowrap> <cfif #image_name# neq ""> <cfif fileexists("#session.locale#/pos/images/products/#image_name#") is "Yes"> <cfimage action = "info" source = "../pos/images/products/#image_name#" structname = "myimage"> <cfset w = #myimage.width# + 45> <cfset h = #myimage.height# + 60> <cfoutput> <a href="##" onclick="window.open('zoom_products.cfm?id=#image_name#', '', 'toolbar=0,menubar=0,scrollbars=0,resizable=1,width=#w#,height=#h#'); return false;"><img src="../pos/images/products/#image_name#" width="100" border="4"><br> (Click To Zoom)</a> </cfoutput> <cfelse><img src="../pos/images/products/PHOTO%20NOT%20AVAILABLE%20label.JPG" width="100" border="4"> </cfif> <cfelse><img src="../pos/images/products/PHOTO%20NOT%20AVAILABLE%20label.JPG" width="100" border="4"> </cfif> Code (markup): It is reading the information contained in the database. However, it displays the image photo not available. Yet, it will display the text of the record of "#image_name" if I add a line to print its contents to screen. (it does provide the space characters though). All replies are very much appreciated. Thanks for your time.
If the code is not displaying the image most likely your path is wrong. So output the path. Is it valid and does the file really exist? Not to mention, your cfimage tag uses a different path. path = #session.locale#/pos/images/products/#image_name#<br> exists? = #fileexists("#session.locale#/pos/images/products/#image_name#")#<br> Code (markup): 1. Though logic seems a little convoluted. It could be written more simply as: <cfif len(image_name) and fileexists("#session.locale#/pos/images/products/#image_name#")> display the image <cfelse> do something else </cfif> Code (markup): 2. It'd be more efficient to store the dimensions in the db, rather than reading them on the fly > <cfset w = #myimage.width# + 45> 3. You've got a lot extra # signs in the code. Most are not needed and can be removed.
cfStarlight, thanks for the reply, I'm really missing something here being so new, My image will display with the last line of code in the below code, which makes me believe the paths are correct and the image exists. I just can't make this display where I wish. <cfloop query="getrecord"> <tr bgcolor="ffffff"> <td align=center valign=middle nowrap> <cfif #image_name# neq ""> <cfif fileexists("#session.locale#/pos/images/products/#image_name#") is "Yes"> <cfimage action = "info" source = "../pos/images/products/#image_name#" structname = "myimage"> <cfset w = #myimage.width# + 45> <cfset h = #myimage.height# + 60> <cfoutput> <a href="##" onclick="window.open('zoom_products.cfm?id=#image_name#', '', 'toolbar=0,menubar=0,scrollbars=0,resizable=1,width=#w#,height=#h#'); return false;"><img src="../pos/images/products/#image_name#" width="100" border="4"><br> (Click To Zoom)</a> </cfoutput> <cfelse><img src="../pos/images/products/PHOTO%20NOT%20AVAILABLE%20label.JPG" width="100" border="4"> </cfif> <cfelse><img src="../pos/images/products/PHOTO%20NOT%20AVAILABLE%20label.JPG" width="100" border="4"> </cfif> </td> <td align=left valign=top nowrap> <table align="left" cellpadding="0" cellspacing="0" border=0> <cfoutput> <cfset #cena_without# = #msrp#> <cfset #new_local_retail# = #street_price_oem#> <tr> <img src="../pos/images/products/#image_name#"> Code (markup): The image displays with the last line of code, however will not in the previous tab, even if I substute PHOTO%20NOT%20AVAILABLE%20label.JPG with #image_name#. I really appreciate your patience and truly wish to learn and understand.
I'm sorry I don't know what you mean by "tab". All I see is <table>'s. Maybe post a screen shot of the problem?
cfStarlight, Thanks again, Here is a screen shot: The code original posted displays this The code in second post displays this, however even substituting #image_name# for "PHOTO%20NOT%20AVAILABLE%20label.JPG" will not display the photo for #image_name# I really appreciate your time.
OK, I've found the line of code creating the problem: <cfif fileexists("#session.locale#/pos/images/products/#image_name#") is "Yes"> Code (markup): If I change "Yes" to "No" my image appears correctly, however my file exists. I don't understand, what am I missing? It couldn't display the selected file if it didn't exists, it would display the "photo not available" image. I really hope someone can explain.
I don't see a screen shot in your previous reply. Did you try my previous suggestion? The best way to figure out problems like this is to output the information and see what's actually going on. Otherwise, you'll just end up going in circles ... Also, for functions that return a boolean (ie true/false, yes/no...) you don't really need to use EQ "yes". Just use <cfif FileExists("c:\somePath\yourFile.txt")> file exists. do something <cfelse> doesn't exist. </cfif>
cfStarlight, I did try your suggestions, as I am continuing to do. Most if not all is my lack of understanding ColdFusion. I am trying to read everything I can. I had clipped two of my screens to show you what I was running into. You provided a great deal of help, and possibly I'm not providing what you expect due to my knowledge here. I had tried copying your code and pasting, and following ColdFusions error suggestions. I do value the time and effort you've gave. It is most appreciative. People such as I who are new don't understand why some don't answer their questions or give them the answer. It is difficult to help a person with limited knowledge, just simple things are often difficult to understand. I don't wish for someone to fix my problem, I wish to understand and work out the problem so I understand for the future problems. I'm still trying everything, even though I can live with my results currently, I do wish for it to be right. Again Thank You!
Well you are welcome, and yes it's tough when you're new to a language. Sometimes the difficult part is knowing the right "term" for things. I can't tell you how many times I've searched futilely because I was using the wrong term. Once I spent hours searching and finally realized the right "technical term" for what I needed, how much easier it was. If only I'd known that hours before Unfortunately, I didn't see any screen shot images in your post. Are you sure you attached them? Or maybe this forum doesn't allow new users to post images until they've gained a certain status or number of posts?). Anyway, sorry I wasn't much help there. What I was suggesting was adding some debugging code to your loop. So you could see why the CFIF isn't acting the way you expect. If you add this code inside your loop you should see two things for each #image_name#: 1) The path of the image being used in your CFIF statement AND 2) The result of fileexists(). ie Whether CF thinks that path exists or not. A typical error is to use the wrong path. You may be able to spot it more quickly if you see the values on the screen. Make sense? <cfloop query="getrecord"> DEBUGGING: (ie check the actual values being used...)<br> <cfoutput> path = #session.locale#/pos/images/products/#image_name#<br> exists? = #fileexists("#session.locale#/pos/images/products/#image_name#")#<br> </cfoutput> </cfloop> Code (markup):
cfStarlight. This is what debug returned: DEBUGGING: (ie check the actual values being used...) path = /var/www/web15/web/pos/images/products/H29 whited 1finished.jpg exists? = NO This is the answer. The web site was at web15 prior to Our Servers Drive reaching threshold, now the web-site is at web2 so the path is incorrect in my code and needs to be changed to web2 This is the help I needed and the answer you stated in the being, but my hard head didn't get it. Your are great and a special thanks for finding my problem. Let me know if there is anything I may do in return. (Hint Mr. Print) Problem: SOLVED, thanks to cfStarlight