Jump to content

I need some help with the IF command...


Jim R

Recommended Posts

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

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>';

Link to comment
Share on other sites

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. 

 

 

 

Link to comment
Share on other sites

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! ;)

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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/

 

 

 

Link to comment
Share on other sites

:)

 

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.


Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.