TechMistress Posted January 9, 2010 Share Posted January 9, 2010 I have a page that lists property listings assigned to a specific user (a manage page), with brief text details and a picture. Each of these listings has several images with it, that aren't seen unless they click on the listing itself to edit/view it. I'd like to put a warning next to the listing on this manage page if one or more of the images assigned to that listing id are over a certain size. I'm not quite sure how to do this. When I put in the code, I get an error at the top giving an filesize stat warning, listing all of the files run together: Warning: filesize() [function.filesize]: stat failed for re_images/1263001649_offer_christmasstory.jpg|1263001038_offer_TEST.jpg in Here is the code I've got that has the problem: if($rows > '0') { $ListingTable .= "<table align=center width=510 border=1 bordercolor=black frame=hsides rules=rows cellspacing=0>\n"; while($a1 = mysql_fetch_array($r1)) { $size = filesize('re_images/'.$a1[image]); if( $size > 153600 ) { echo '<p align=center><img src="images/warning.gif" border="0"></p>'; $warning="<font color=#FF0000 size=5>!!</font></b>"; } $ListingTable .= "<tr onMouseOver=\"this.style.background='#E2E2E2'; this.style.cursor='hand'\" onMouseOut=\"this.style.background='white'\" onClick=\"window.open('info.php?id=$a1[ListingID]', '_top')\">\n\t"; if($a1[PriorityLevel] > '1') { //get the priority level name $qp = "select PriorityName from re2_priority where PriorityLevel = '$a1[PriorityLevel]' "; $rp = mysql_query($qp) or die(mysql_error()); $ap = mysql_fetch_array($rp); $sub = "<span class=RedLink><sup>$ap[0]</sup></span>"; } else { $sub = ""; } $ListingTable .= "\n\t<td width=15>"; if(!empty($a1[image])) { $ListingTable .= "<img src=\"myimages/camera.jpg\" width=15 height=15>$warning"; } $ListingTable .= "</td>\n\t"; $ListingTable .= "<td width=305>$a1[city], $a1[state], $a1[address] $sub</td>\n\t"; $ListingTable .= "<td width=80>$a1[rooms] br, $a1[bathrooms] ba"; $MyPrice = number_format($a1[Price], 2, ".", ","); $ListingTable .= "</td>\n\t<td align=center width=100><b>$$MyPrice</td>\n"; $ListingTable .= "</tr>\n"; } $ListingTable .= "</table>"; } I've coded this on the next page that shows all of the image, and it worked good. This one, I just couldn't figure out how to tell the server to look in the folder to see if any of the image associated with an id are a certain size. Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/ Share on other sites More sharing options...
wildteen88 Posted January 9, 2010 Share Posted January 9, 2010 How is your database structured? Specifically the image column. Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/#findComment-991786 Share on other sites More sharing options...
crabfinger Posted January 9, 2010 Share Posted January 9, 2010 What does $a1['image'] return? Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/#findComment-991788 Share on other sites More sharing options...
TechMistress Posted January 9, 2010 Author Share Posted January 9, 2010 Well, it's almost working - it's reading the files associated to the specific listing, but I think I have an extra loop in there or something, since it's giving me this error: Warning: filesize() [function.filesize]: stat failed for re_images/1263001649_offer_christmasstory.jpg|1263001038_offer_TEST.jpg in Those are the images for that listing, but they are running together. When someone creates a listing, they upload images with it. The system renames the image and puts it in the re_images folder, then lists the names of those images in the database table called 'image'. I was going to avoid all of this if I could somehow figure out how to check for image size on upload, but I couldn't get that to work, since php needs to check size after it's been uploaded. Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/#findComment-991797 Share on other sites More sharing options...
crabfinger Posted January 9, 2010 Share Posted January 9, 2010 try print $a1['image']; remember that if you don't have the right input, your output won't be right. Or "Garbage in, Garbage out" Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/#findComment-991847 Share on other sites More sharing options...
TechMistress Posted January 9, 2010 Author Share Posted January 9, 2010 well, i'm not looking to print a list of images, i'm looking for an if/then statement: "if one of the images assigned to this listing id is too big, then output an error" I'm checking the size of the images assigned to the current listing. However, I get the filesize error above. Those are indeed the images, but it's reading them all together. Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/#findComment-991848 Share on other sites More sharing options...
wildteen88 Posted January 9, 2010 Share Posted January 9, 2010 When someone creates a listing, they upload images with it. The system renames the image and puts it in the re_images folder, then lists the names of those images in the database table called 'image'. Judging by your error message it looks like you are storing all images as image1.jpg|image2.jpg|etc.... The problem is filesize does not know that you giving it a list of images to check the file size of. It expects only a single file name to be passed. You'll need to convert the list of images into an array, using explode. Then you can for loop through the array and pass each image separately to the filesize() function Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/#findComment-991853 Share on other sites More sharing options...
crabfinger Posted January 9, 2010 Share Posted January 9, 2010 I told you to try that because we want to know what is in the variable if the contents of the variable are formatted incorrectly then you will have a problem. It's called dubugging, use it. Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/#findComment-991859 Share on other sites More sharing options...
TechMistress Posted January 9, 2010 Author Share Posted January 9, 2010 aha! That's why it worked on the other page, the explode element. As you can see, I've never programmed before, and I'm trying to teach myself. I'll let you know how it goes! I appreciate you all trying to figure out my problem with probably a HUGE lack of correct information. Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/#findComment-991866 Share on other sites More sharing options...
TechMistress Posted January 9, 2010 Author Share Posted January 9, 2010 Hey, it worked!! I knew you guys could lead me in the right direction. Here's the code (messy): if(!empty($a1[image])) $MyImages = explode("|", $ap[image]); while(list(,$vi) = each($MyImages)) { $size = filesize('re_images/'.$vi); if( $size > 153600 ) { echo '<p align=center><img src="images/warning.gif" border="0"></p>'; $warning="<font color=#FF0000 size=5>!!</font></b>"; } { $ListingTable .= "<img src=\"myimages/camera.jpg\" width=15 height=15>$warning"; } $ListingTable .= "</td>\n\t"; $ListingTable .= "<td width=305>$a1[city], $a1[state], $a1[address] $sub</td>\n\t"; $ListingTable .= "<td width=80>$a1[rooms] br, $a1[bathrooms] ba"; $MyPrice = number_format($a1[Price], 2, ".", ","); $ListingTable .= "</td>\n\t<td align=center width=100><b>$$MyPrice</td>\n"; $ListingTable .= "</tr>\n"; } } $ListingTable .= "</table>"; } Quote Link to comment https://forums.phpfreaks.com/topic/187844-is-this-possible-if-one-file-assigned-to-an-id/#findComment-991868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.