jasonmbrown Posted March 11, 2009 Share Posted March 11, 2009 ok well im just starting to learn php and im having a little bit of trouble with one of my if statements its supposed to check if a filename ends in a valid picture format however if i use && or || i still get the same output. as if its not even checking the file extension. Did i make a mistake when getting the file extension? <?php $ofile = fopen ("imgs/gallery.xml", "w+"); fwrite($ofile,'<tiltviewergallery><photos>'); $handle= opendir("imgs"); while (false !== ($file = readdir($handle))) { $x = strlen($file); while ($x > -1){ if (substr($file,$x, 1) == '.') { $filext = substr($file,$x + 1); fwrite(fopen("debug.txt","w+"),substr($file,$x, 1)); } $x=$x - 1; } if (strcasecmp($filext,"jpg" == 0) && strcasecmp($filext,"png" == 0) && strcasecmp($filext,"gif" == 0) && strcasecmp($filext,"bmp" == 0) && strcasecmp($filext,"jpeg" == 0) && strcasecmp($filext,"tif" == 0) && strcasecmp($filext,"tiff" == 0)) { fwrite($ofile,' <photo imageurl="imgs/'.$file.'"> </photo>'); } } fwrite($ofile,'</photos></tiltviewergallery>'); fclose($ofile); ?> thanks before hand Welll now im an idiot sorry for bothering people. It should have been if (strcasecmp($filext,"jpg") == 0) Link to comment https://forums.phpfreaks.com/topic/149010-probably-pathetic-problem-with-an-if-statement/ Share on other sites More sharing options...
Mchl Posted March 11, 2009 Share Posted March 11, 2009 Welll now im an idiot sorry for bothering people. The fact that you managed to find the mistake by yourself does not make you an idiot. I'd say it's the other way round. Everyone makes silly mistakes from time to time. Link to comment https://forums.phpfreaks.com/topic/149010-probably-pathetic-problem-with-an-if-statement/#findComment-782500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.