seany123 Posted March 21, 2012 Share Posted March 21, 2012 I have this page which displays images from a folder based on entries to a mysql table. with this code everything works fine: while($query_row = mysql_fetch_assoc($query)) { echo "<img src='uploads/".$cat."/".urlencode($query_row['url'])."'/>  "; if ($i==5){echo"<br><br>"; $i=0;} $i++; } the problem occurs when i try and add this code instead while($query_row = mysql_fetch_assoc($query)) { //this gets the images information and sets the height and width if too high! $info = getimagesize("uploads/".$cat."/".urlencode($query_row['url']).""); $height = $info[1]; $width = $info[0]; if ($height > 500){ $height = 500; } if ($width > 500){ $width = 500; } echo "<img src='uploads/".$cat."/".urlencode($query_row['url'])."' height='".$height."' width='".$width."'/>  "; if ($i==5){echo"<br><br>"; $i=0;} $i++; } it throws out errors like this: Warning: getimagesize(uploads/cakes/imagejpg.jpg) [function.getimagesize]: failed to open stream: No such file or directory on line 31 so whats wrong with this line? $info = getimagesize("uploads/".$cat."/".urlencode($query_row['url']).""); i know i have a double quotation but im tired and i cant think how to fix that atm, although im not sure if thats the problem or not? Sean Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/ Share on other sites More sharing options...
azukah Posted March 21, 2012 Share Posted March 21, 2012 have you tried absolute path or just "../" or "/" i had the same error (not finding my directory) so where's your uploads folder? in the same root as the file where this code is or somewhere else? Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329700 Share on other sites More sharing options...
seany123 Posted March 21, 2012 Author Share Posted March 21, 2012 have you tried absolute path or just "../" or "/" i had the same error (not finding my directory) so where's your uploads folder? in the same root as the file where this code is or somewhere else? yes i have tried both ../ and / (neither worked) the uploads folder is in the same root folder that the script file is in, i know that it shouldn't be a not finding directory error because ALL the images are in the exact same folder, however not ALL the images are giving this error, some in fact most are working fine, the page shows 100 images and only around 2-3 are failing with this error which i find weird. Sean Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329702 Share on other sites More sharing options...
azukah Posted March 21, 2012 Share Posted March 21, 2012 do you have firebug or an other inspector? try inspecting the path of an image that's not showing, that way you can see where is trying to pull the image from and if the path is correct, make sure the images are uploaded to the server. Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329703 Share on other sites More sharing options...
seany123 Posted March 21, 2012 Author Share Posted March 21, 2012 do you have firebug or an other inspector? try inspecting the path of an image that's not showing, that way you can see where is trying to pull the image from and if the path is correct, make sure the images are uploaded to the server. no i dont have firebug or any other inspector, ill look into it though... The image is STILL showing, but its show along with the error. live example in my signature... the error is appearing on every image now, however the images are still displaying. Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329705 Share on other sites More sharing options...
dragon_sa Posted March 21, 2012 Share Posted March 21, 2012 The problem is the () you are using in the file names, they are breaking your code, change your image names and dont use special characters like (){}[]/! Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329708 Share on other sites More sharing options...
seany123 Posted March 21, 2012 Author Share Posted March 21, 2012 The problem is the () you are using in the file names, they are breaking your code, change your image names and dont use special characters like (){}[]/! thats what urlencode() is for?? Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329852 Share on other sites More sharing options...
AyKay47 Posted March 21, 2012 Share Posted March 21, 2012 The browser decodes the string automatically, PHP doesn't. Warning: getimagesize(uploads/cakes/CreamCakes_%2810%29.jpg) [function.getimagesize]: failed to open stream: No such file or directory in the error is pretty obvious, do you have a file named 'CreamCakes_%2810%29.jpg'? And yeah, keep your file names simple to avoid this all together. Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329854 Share on other sites More sharing options...
onlyican Posted March 21, 2012 Share Posted March 21, 2012 HTM Tag img src="X" takes from website root Whereas getimagesize() taks from Web Server Root Try something like $imageFile = $_SERVER['DOCUMENT_ROOT']."uploads/".$cat."/".urlencode($query_row['url']); if(file_exists($imageFile){ $info = getimagesize("uploads/".$cat."/".urlencode($query_row['url']).""); // Continue rest of code; }else{ // add debug for file not found } Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329867 Share on other sites More sharing options...
seany123 Posted March 21, 2012 Author Share Posted March 21, 2012 The browser decodes the string automatically, PHP doesn't. Warning: getimagesize(uploads/cakes/CreamCakes_%2810%29.jpg) [function.getimagesize]: failed to open stream: No such file or directory in the error is pretty obvious, do you have a file named 'CreamCakes_%2810%29.jpg'? And yeah, keep your file names simple to avoid this all together. yes that image exsists and is being displayed just above the error message HTM Tag img src="X" takes from website root Whereas getimagesize() taks from Web Server Root Try something like $imageFile = $_SERVER['DOCUMENT_ROOT']."uploads/".$cat."/".urlencode($query_row['url']); if(file_exists($imageFile){ $info = getimagesize("uploads/".$cat."/".urlencode($query_row['url']).""); // Continue rest of code; }else{ // add debug for file not found } the file does exist though and is being displayed... Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329878 Share on other sites More sharing options...
AyKay47 Posted March 21, 2012 Share Posted March 21, 2012 You didn't read my reply thoroughly, re-read it, then re-read it again. Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329880 Share on other sites More sharing options...
onlyican Posted March 21, 2012 Share Posted March 21, 2012 The file may exist but <img src="X" /> AND getimagesize() looks at different levels. Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329881 Share on other sites More sharing options...
dragon_sa Posted March 21, 2012 Share Posted March 21, 2012 just as a test to show what is being said about the filename, change 1 filename in your database and in the image directory, i suggest this one uploads/cakes/CreamCakes_%281%29.jpg to uploads/cakes/CreamCakes_1.jpg and I bet the error goes away for that first image, the web browser treats the %28 and %29 as brackets but the php script does not do this causing the error so in the script that file does not exist but in the web browser it does Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1329886 Share on other sites More sharing options...
seany123 Posted March 22, 2012 Author Share Posted March 22, 2012 just as a test to show what is being said about the filename, change 1 filename in your database and in the image directory, i suggest this one uploads/cakes/CreamCakes_%281%29.jpg to uploads/cakes/CreamCakes_1.jpg and I bet the error goes away for that first image, the web browser treats the %28 and %29 as brackets but the php script does not do this causing the error so in the script that file does not exist but in the web browser it does after looking into my directory i realised that there was not a image called that... its actually called: CreamCakes_(1).jpg Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1330052 Share on other sites More sharing options...
dragon_sa Posted March 22, 2012 Share Posted March 22, 2012 thats right and your urlencode is changing () to %28 and %29, while the web browser translates that back to brackets the php script wont, change the image name to remove the brackets and it should resolve your problem Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1330053 Share on other sites More sharing options...
seany123 Posted March 22, 2012 Author Share Posted March 22, 2012 thats right and your urlencode is changing () to %28 and %29, while the web browser translates that back to brackets the php script wont, change the image name to remove the brackets and it should resolve your problem Hmm is there no way to handle that? Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1330054 Share on other sites More sharing options...
dragon_sa Posted March 22, 2012 Share Posted March 22, 2012 you could try removing urlencode and then something like str_replace to escape the brackets, but its really not good practice to use special characters in filenames. Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1330055 Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2012 Share Posted March 22, 2012 Don't use urlencode on the value you put into the getimagesize() statement. Like its name indicates, urlencode is used in URLs. The value you output on your page in the <img src="..."> tag is a URL, the value you use in getimagesize() is a file system path. Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1330056 Share on other sites More sharing options...
seany123 Posted March 22, 2012 Author Share Posted March 22, 2012 yes removing the urlencode worked a treat and i no longer get any errors, i didnt wish to change the image names because i currently have over 5k images and although im sure i could create some type of renaming script, this seemed much easier! Thanks! solved Quote Link to comment https://forums.phpfreaks.com/topic/259385-why-am-i-getting-this-error/#findComment-1330059 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.