thefollower Posted October 21, 2008 Share Posted October 21, 2008 I need some help with my if statement. I have a check to see if an image exists in my database... and if it does not .. then delete the row that is still trying to load it... but it never finds the image even if the directory is correct :S This is what i have: <?php $Get = mysql_query("SELECT Image,RecordID FROM userimages WHERE UserID='{$_SESSION['Current_User']}' AND ApprovedBY !='0'") Or die(mysql_error()); While($row = mysql_fetch_assoc($Get)){ $Image = $row['Image']; $Check = '/images/userprofiles/'.$Image; Echo $Check; Echo '<br>'; $RecordID = $row['RecordID']; if (file_exists($Check)) { ?> <img src="/images/userprofiles/<?=$Image?>" width="150px" height="200px"> <?php }Else{ $DELETE = mysql_query("DELETE FROM userimages WHERE RecordID='$RecordID'") Or die(mysql_error()); } ?> What am i doing wrong? =/ For the record if i change it to <?php If(!(file_exist($Check))){ } ?> It still deleted it =/ Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/ Share on other sites More sharing options...
ghostdog74 Posted October 21, 2008 Share Posted October 21, 2008 specifying /images/userprofiles/ means your image file exists under the root directory's "image" directory. if you want to check whether your image file exists in the current directory, you might want to add a dot in front -> "./image/userprofiles" instead Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670659 Share on other sites More sharing options...
thefollower Posted October 21, 2008 Author Share Posted October 21, 2008 You've lost me ? The file in which this script has that in is the root And in the root i have a folder named images with a subfolder userprofiles Wouldn't that mean its correct at present? Example: Root: file.php images ¬ useprofiles ¬ name.jpg Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670661 Share on other sites More sharing options...
hellonoko Posted October 21, 2008 Share Posted October 21, 2008 Doesn't breaking out PHP in a loop typically mess things up? Try echo "<img src="/images/userprofiles/".$Image." width="150px" height="200px">"; Maybe? Maybe I am way off. Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670671 Share on other sites More sharing options...
Zane Posted October 21, 2008 Share Posted October 21, 2008 You've lost me ? The file in which this script has that in is the root And in the root i have a folder named images with a subfolder userprofiles Wouldn't that mean its correct at present? Example: Root: file.php images ¬ useprofiles ¬ name.jpg he doesn't mean your webroot. He means the root of your partition. EDIT: try using file_exists(realpath("./images/userprofiles/name.jpg")); Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670676 Share on other sites More sharing options...
thefollower Posted October 21, 2008 Author Share Posted October 21, 2008 Oh ok ... well it works.. so thats good.. don't get why when displaying it in html though i don't need the " ./ " Thanks Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670681 Share on other sites More sharing options...
d_barszczak Posted October 21, 2008 Share Posted October 21, 2008 Your web root is entirely different from your root directory. Think of / in linux as your C:\ and ./ as your current working directory. Your web root is usually something like /home/username/public_html/ By using ./images/image.jpg you are looking for /home/username/public_html/images/image.jpg and by using /images/image.jpg you are using /images/image.jpg you are looking for just that. Hope this helps you understand a little better. Do a little research on linux filesystems. Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670687 Share on other sites More sharing options...
Zane Posted October 21, 2008 Share Posted October 21, 2008 Oh ok ... well it works.. so thats good.. don't get why when displaying it in html though i don't need the " ./ " Because HTML is client side. As far as the "HTML Server" AKA the web server (Apache/IIS) is concerned THIS Root: file.php images ¬ useprofiles ¬ name.jpg Is your root....or else everyone on the net would have access to all the files on your computer (unless of course you set restrictions.....very well) PHP is server side. And since it is....it already has access to all of your computer so it looks at your computer as a whole. Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670690 Share on other sites More sharing options...
d_barszczak Posted October 21, 2008 Share Posted October 21, 2008 ./ in html is not required because it does not have access to the linux root whereas php does. Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670691 Share on other sites More sharing options...
thefollower Posted October 21, 2008 Author Share Posted October 21, 2008 So should all my includes... do the same ? like if i did : include("/foldername/subfolder/file.php"); or should that also have ./ aswell ? Because it works without the dot in that situation Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670693 Share on other sites More sharing options...
d_barszczak Posted October 21, 2008 Share Posted October 21, 2008 I think if you miss out the first / that should work also: images/ not /images/ Quote Link to comment https://forums.phpfreaks.com/topic/129367-solved-file-exist-check/#findComment-670772 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.