Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 Nope. Again, the problem isn't with the path to right folder. It appears to get it all right until file format. It clearly prints the .JPG correctly. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1002906 Share on other sites More sharing options...
Yucky Posted January 28, 2010 Share Posted January 28, 2010 I've just noticed that there's more than one valid path to each image. For example: http://hoosierhoopsreport.com/wp-content/uploads/HutsonAlexander.JPG http://hoosierhoopsreport.com/tag/wp-content/uploads/HutsonAlexander.JPG Are the images uploaded in both folders, or is there some trickery going on? If /tag/ is the actual path then it would explain everything. If it's the case, you'd need $file_name = "../tag/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".jpg"; if (!file_exists($file_name)) $file_name = "../tag/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".JPG"; echo '<div><img src="' . $file_name .'" /></div>'; Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1002907 Share on other sites More sharing options...
Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 No, that's a Wordpress feature, dealing with taxonomy, and I don't fully understand it. However, you can replace the 'tag' with any word, such as yucky. http://hoosierhoopsreport.com/yucky/wp-content/uploads/HutsonAlexander.JPG The file is in wp-content/uploads folder. That's a folder I use specifically for head shots, specifically for my wp-playerProfile.php. I tried it...same result. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1002910 Share on other sites More sharing options...
Yucky Posted January 28, 2010 Share Posted January 28, 2010 This forum doesn't keep users logged in for very long, does it? Third time lucky posting this! I'm a bit stumped here as it worked for me, but two suggestions: 1) Try giving the uploaded/images folder 777 permissions temporarily. It seems unlikely, but perhaps the PHP user doesn't have read access to the folder. 2) Failing that, try using a full path to the images. You can get the path using: echo $_SERVER['DOCUMENT_ROOT']; It'll look something like: /home/your-user/public_html/etc You'd need to change the code to reflect this: $file_name = "/home/user/public_html/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".jpg"; if (!file_exists($file_name)) echo "File not found!"; echo '<div><img src="' . $file_name .'" /></div>'; If that works work then we'll have to rejig the code a bit for the output path. Hopefully it'll be the first suggestion though! Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1002912 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 I think perhaps completely misunderstood what you wanted then or what the real issue is? Between Yucky and my original posts you should have had the issue solved as far as we could see it. Need some more information and my code didn't have echos because assumed you'd put them in... they were to try and I had not tried them sorry, but they should have worked if implemented correctly. Guess I may need more info to try to fix your problem I guess. I think I am misunderstanding why it will not print the ".jpg" and will the ".JPG" since if that was the issue then it is simply check if one is valid then go on and if not then do the next one. or even just scan the directory may work I'm a bit stumped here as it worked for me, but two suggestions: 1) Try giving the uploaded/images folder 777 permissions temporarily. It seems unlikely, but perhaps the PHP user doesn't have read access to the folder. 2) Failing that, try using a full path to the images. You can get the path using: echo $_SERVER['DOCUMENT_ROOT']; Thats a good idea just to check anyways, Yucky, but doubt it's the issue since he can get one and not the other. I'm just confused on what the issue is?!?!? I gave an if to answer the simple question and think there is still something else wrong... and if only the ."JPG" or ".jgp" will print then there is an issue with the path... If you just echo out both image paths does one or the other always show up? I mean is it really just an appendix name issue? If so give code for that location... Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1002995 Share on other sites More sharing options...
Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 I know the paths are correct because when I just have both echo statements, they work as they are written, either a placeholder then an image or an image then a placeholder. You can see that with these two players: If it's a .JPG file it goes placeholder then image: http://hoosierhoopsreport.com/tag/alexander-hutson/ If it's a .jpg file it goes image then placeholder: http://hoosierhoopsreport.com/tag/deshaun-thomas/ Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003029 Share on other sites More sharing options...
aebstract Posted January 28, 2010 Share Posted January 28, 2010 I went straight to your last post, so this may be very unhelpful, but: <div class="player"><div><img src="/wp-content/uploads/HutsonAlexander.jpg"></div><div><img src="/wp-content/uploads/HutsonAlexander.JPG"></div> How come you have the image twice? Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003031 Share on other sites More sharing options...
Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 When I started the site, my pre-existing images were all .jpg files. The software I'm using with my new camera converts everything to .JPG files, and I can't change that setting to .jpg. Instead of changing all my previous files or altering all my new ones, I have both echo statements. Now we are trying to get it to just recognize the one that exists. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003036 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 Ok I'm sorry seemed to got lost in translation there... ok stepping back. I understand the issue and a simple if statement should have fixed that like you thought. But it's not.... hmmmm... Now I'm baffled on why not. At least this is interesting.... Just sudo code but make sure we've hit all the bases here again... IF (THIS PATH IMAGE ."jpg" EXISTS) ECHO OUT "jpg" image ELSE ECHO OUT "JPG" image This what we want to do correct? I tried to recreate the issue and was unsuccessful at doing so, my server I'm working off makes it a non issue. Sorry. I guess best I can do is lead in the right direction. Oh well if you find a fix let us know, it's been an interesting case though. I am at a lost however. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003042 Share on other sites More sharing options...
Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 That's exactly what I want, and it looks so darn simple. Just doesn't seem to take. It seems to bypass recognition of the .jpg file when it exists. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003051 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 That's exactly what I want, and it looks so darn simple. Just doesn't seem to take. It seems to bypass recognition of the .jpg file when it exists. Yeah that's why I am lost, and I've seen similar problems before dealing a windows server specifically actually. Out of curiosity not using a windows server to host that are you? Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003054 Share on other sites More sharing options...
Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 Linux centOS on the server. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003056 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 There goes that theory... lol. Anyways... I wish I had a magic button function. But I'd thought that if statement would fix it, yet sort of understand why it doesn't. Bugs me that can't figure this out ha... oh well. Another way of doing it would be to check if it exists and just echo it a string just to see what php is actually seeing.... Cool recreated the issue you had with this... this script works for me, but think you've already tried it anyways. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003063 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 Sorry didn't have a fix and didn't modify last post in time. Thought I did but did not. Well hard way will always work... converting all the old images to reflect your new camera standard and changing code to reflect that. It is the hard way and time consuming but nonetheless will work if all else fails. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003069 Share on other sites More sharing options...
Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 I'm using this now just to test it: $file_name = "/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".jpg"; if (!file_exists($file_name)) echo 'hello'; No matter what, it prints hello. So it's not differentiating whether or not the .jpg file exists, which is what I expected. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003080 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 I'm using this now just to test it: $file_name = "/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".jpg"; if (!file_exists($file_name)) echo 'hello'; No matter what, it prints hello. So it's not differentiating whether or not the .jpg file exists, which is what I expected. Yeah I got the same issue when I was finally able to recreate your issue on one of the servers I had access to. Couldn't get it to differentiate between upper lower extensions... WTF right!?!?! haha But PHP must intepret all the image file extensions as non-case sensitive. Would have to look that up to try to find an answer to something that should be so simple. I'll get back to you if I find a resolution to that. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003087 Share on other sites More sharing options...
Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 I went into it thinking . jpg / .JPG...eh...to-may-to / to-mah-to, but Wordpress definitely sees the difference. But consider this. The IF condition NEVER sees the .jpg, just goes to the .JPG, so it's not really an issue of not telling the difference between .jpg and .JPG. The IF condition isn't working. Is it a syntax issue? I've tried braces around what follows the IF, but it didn't change anything. if (!file_exists($file_name)) {$file_name = "/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".JPG"}; Perplexing. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003089 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 Hey I have a possible solution just though of though ... a backwards solution but a temp fix that not so bad really.... Ok create a new folder called Image_New or something Then just scan older image folder if the file exists for ".jpg" echo html using the .jpg If if does not then check the new folder for the image in new folder using "JPG" if it exists in new folder then echo html using the JPG This way it should print only one image tag and since the name should never exists in both folders it only prints one line relative to what folder it found it .... instead of relative to the file extension. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003090 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 Is it a syntax issue? I've tried braces around what follows the IF, but it didn't change anything. if (!file_exists($file_name)) {$file_name = "/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".JPG"}; Perplexing. I think it's PHP way of interpretting it... as u said matters in wordpress but not in PHP. .. anyways another syntax way of writing that in case you care is this too. But it will not make a difference I don't think since I believe you are using everything right. Since I can now recreate the issue and can't find a way around it using php alone. BUT there are a few tricks I'll try that I can think of yet... although I doubt they will matter I have a suspicion there is something else at play. I'm not gonna let this go now that you got me entangled in it lol... until one of us finds a working solution anyways. if ( (file_exists($file_name)) == TRUE) { $file_name = "/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".JPG"; } Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003093 Share on other sites More sharing options...
ChemicalBliss Posted January 28, 2010 Share Posted January 28, 2010 A possible debug step to check the file integrity: Make a new file. with the same condition statement, on its own. See if it works. If the new file on its own works you know its something to do with the file your using. Hope this helps, -CB- PS, I have had issues of Windows-to-UNIX ports of Native windows text, essentiually the EOL characters used are different, and can create all sorts of unknown errors. Make sure your files EOL characters are UNIX standard \n (You can use Notepad++ to check and convert the files if necessary). Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003096 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 Try CB's idea. Also try playing with the rename function as well. This will try to change the same thing twice they may both fail / pass / or one pass and the other fail... doesn't matter if it works the new name should always be with a ".jpg" since you do the rename twice.... haven't tested this and no time to at moment but something different to try. Never tried the rename fucntion so may want to look it up to make sure I'm using it right. $old_name = "/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".JPG"; $old_name_2 = "/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".jpg"; $new_name = "image.jpg"; rename($old_name, $new_name ); rename($old_name_2, $new_name); //echo test image here using the $newname Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003104 Share on other sites More sharing options...
Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 $file_name = "/wp-content/uploads/". $line['nameLast'] . $line['nameFirst'] . ".jpg"; if ( (file_exists($file_name)) == TRUE) echo 'Hello'; That isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003164 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 Didn't figure it would...or do you mean it's not compiling whatsoever? At this point and not finding an acceptable alternative I'd really think about putting all the newer photos in a different folder and going about it that way. I am truly at a loss man. Sorry. But if you want ideas of some alternative ways of just setting this up and dealing with this issue let me know and I'll get some sudo code set up for that. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003234 Share on other sites More sharing options...
Jim R Posted January 28, 2010 Author Share Posted January 28, 2010 I just went through and changed all the formats. I probably have some pictures throughout the entirety of my site which now refer to missing images, but the main purpose of this folder is one I now just use on profile (Tag Archive) pages, which are generated with the code we've been messing with. Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003245 Share on other sites More sharing options...
gwolgamott Posted January 28, 2010 Share Posted January 28, 2010 Ok, cool. Well can't say we didn't try, but sometimes the hard road was easier in the beginning. Still this should have been simple, frustrating I have no answer let alone on your end i imagine Quote Link to comment https://forums.phpfreaks.com/topic/190005-i-need-some-help-with-the-if-command/page/2/#findComment-1003257 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.