HOw to check if current file belong to this directory?

#1
[eluser]qpixo[/eluser]
I have a collection of images and they are stored in different specific subdirectory within main directory images.

Ex:
images/indoor/... jpg
images/outdoor/... jpg

What is the simple way to check if the current image is belong to the right directory? If not go to next directory and check... repeat until found it.


#2
[eluser]CroNiX[/eluser]
Code:
if ( ! file_exists('/path/to/images/indoor/image.jpg'))
{
  //not in this dir
}
http://php.net/manual/en/function.file-exists.php

#3
[eluser]CroNiX[/eluser]
However, this isn't really a good or efficient way to solve your issue. I would be storing the category for each image in a database, so it would know that 'image.jpg' is in the 'indoor' category, so look in the 'indoor' dir.

#4
[eluser]qpixo[/eluser]
[quote author="CroNiX" date="1354052371"]However, this isn't really a good or efficient way to solve your issue. I would be storing the category for each image in a database, so it would know that 'image.jpg' is in the 'indoor' category, so look in the 'indoor' dir.[/quote]

I have tried file_exists but it doesn't recognize the path.

Yes I have stored each category for each image in DB.

Ex:

Each subdirectory contains a collection of .jpg
/images/indoor/img_01.jpg... 10.jpg
/images/outdoor/img_01.jpg...20.jpg


#5
[eluser]bretticus[/eluser]
[quote author="qpixo" date="1354045553"]
What is the simple way to check if the current image is belong to the right directory? If not go to next directory and check... repeat until found it.
[/quote]

You really need to elaborate on your problem. What do you mean by the "current image?" If you are using some sort of database category, how does the "current image" correlate?

#6
[eluser]CroNiX[/eluser]
[quote author="qpixo" date="1354059162"][quote author="CroNiX" date="1354052371"]However, this isn't really a good or efficient way to solve your issue. I would be storing the category for each image in a database, so it would know that 'image.jpg' is in the 'indoor' category, so look in the 'indoor' dir.[/quote]

I have tried file_exists but it doesn't recognize the path.

Yes I have stored each category for each image in DB.

Ex:

Each subdirectory contains a collection of .jpg
/images/indoor/img_01.jpg... 10.jpg
/images/outdoor/img_01.jpg...20.jpg

[/quote]

I assume you aren't using a FULL path then, so it's not finding it. If you are only looking for '/images/indoor/file.jpg', then that is going to look in the ROOT directory of the SERVER (not your website root) for a dir 'images'.

Maybe you need to use something like
Code:
file_exists($_SERVER['DOCUMENT_ROOT'] . '/images/indoor/file.jpg');
so it supplies the FULL path to your image, which might actually look something like:
/home/your_site/public_html/images/indoor/file.jpg

#7
[eluser]qpixo[/eluser]
[quote author="bretticus" date="1354093195"][quote author="qpixo" date="1354045553"]
What is the simple way to check if the current image is belong to the right directory? If not go to next directory and check... repeat until found it.
[/quote]

You really need to elaborate on your problem. What do you mean by the "current image?" If you are using some sort of database category, how does the "current image" correlate?[/quote]

Yeah I'm using DB category

Here are my tables and their relationship:

Category
#cat_id
name
position
visible

Page
#page_id
cat_id
name
position
visible

Page_Image
#page_id
#img_id

Images
#img_id
name
url
visible
...

Now I'm having trouble to display each of them on the correct directory. Meaning for: as_012, as_03.jpg and tg_06 files suppose to be only in outdoor directory. Obviously something wrong with my db request...

Display in a pagination


http://site/images/outdoor/as_012.jpg
http://site/images/outdoor/as_03.jpg
http://site/images/outdoor/tg_06.jpg
http://site/images/indoor/as_012.jpg
http://site/images/indoor/as_03.jpg
http://site/images/indoor/tg_06.jpg

1|2|3 > last


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.