Jump to content

[SOLVED] File Exist check?


thefollower

Recommended Posts

I need some help with my if statement.

 

I have a check to see if an image exists in my database... and if it does not .. then delete the row that is still trying to load it... but it never finds the image even if the directory is correct :S

 

This is what i have:

 

<?php
$Get = mysql_query("SELECT Image,RecordID FROM userimages WHERE UserID='{$_SESSION['Current_User']}' AND ApprovedBY !='0'")
Or die(mysql_error());

While($row = mysql_fetch_assoc($Get)){
$Image = $row['Image'];
$Check = '/images/userprofiles/'.$Image;
Echo $Check;
Echo '<br>';
$RecordID = $row['RecordID'];

if (file_exists($Check)) {
?>

<img src="/images/userprofiles/<?=$Image?>" width="150px" height="200px">

<?php
	}Else{
	$DELETE = mysql_query("DELETE FROM userimages WHERE RecordID='$RecordID'")
		Or die(mysql_error());
}
?>

 

What am i doing wrong? =/

 

For the record if i change it to

<?php
If(!(file_exist($Check))){
}
?>

 

It still deleted it =/

Link to comment
Share on other sites

You've lost me ?

 

The file in which this script has that in is the root

 

And in the root i have a folder named images with a subfolder userprofiles

 

Wouldn't that mean its correct at present?

Example:

 

Root:

file.php

images ¬

        useprofiles ¬

                name.jpg

Link to comment
Share on other sites

You've lost me ?

 

The file in which this script has that in is the root

 

And in the root i have a folder named images with a subfolder userprofiles

 

Wouldn't that mean its correct at present?

Example:

 

Root:

file.php

images ¬

         useprofiles ¬

                name.jpg

he doesn't mean your webroot.  He means the root of your partition.

 

EDIT: try using file_exists(realpath("./images/userprofiles/name.jpg"));

Link to comment
Share on other sites

Your web root is entirely different from your root directory.

 

Think of / in linux as your C:\ and ./ as your current working directory. Your web root is usually something like /home/username/public_html/

 

By using ./images/image.jpg you are looking for /home/username/public_html/images/image.jpg and by using /images/image.jpg you are using /images/image.jpg you are looking for just that. Hope this helps you understand a little better.

 

Do a little research on linux filesystems.

Link to comment
Share on other sites

Oh ok ...  well it works.. so thats good.. don't get why when displaying it in html though i don't need the " ./ "

Because HTML is client side.  As far as the "HTML Server" AKA the web server (Apache/IIS) is concerned

THIS

Root:

file.php

images ¬

        useprofiles ¬

                name.jpg

Is your root....or else everyone on the net would have access to all the files on your computer (unless of course you set restrictions.....very well)

 

PHP is server side.  And since it is....it already has access to all of your computer so it looks at your computer as a whole.

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.