Jump to content

Recommended Posts

So I am trying to tweak a few things on a page and I am stuck on this one. I want the ###### to also be the data in $row['id']

 

<?php
if (file_exists('/var/www/html/images/races/######/images/' . $row['id'] . $dthumb)):
?>

 

so if $row['id'] = 124 it would be looking for

 

/var/www/html/images/races/124/images/124.jpg'))

 

I know it has to be that I am stumped on the correct question to ask or search for.

 

Any help is appreciated.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/255688-need-help-in-this-statement-please/
Share on other sites

 $row['id'] = (int)$row['id']; // cast to int to make sure nothing bad gets through.
if (file_exists('/var/www/html/images/races/' . $row['id'] .'/images/' . $row['id'] . $dthumb)):

 

Should do what you want. This is called concatenation. I also statically cast the id to an integer, as that is what you are expecting and this will make sure that something weird doesn't go through that could be used to get information about your site (more than likely not, but better save than sorry).

 

Also, instead of manually typing the path in like that, I would use $_SERVER['DOCUMENT_ROOT'], if possible.

 

if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/images/races/' . $row['id'] .'/images/' . $row['id'] . $dthumb)):

 

Assuming that has been set by your webserver and it is set to /var/www/html

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.