Jump to content

file_exists problems


jonlivesley

Recommended Posts

Hey.

 

I have an issue with the file_exists function not working as expected and I haven't been able to crack it anyhow despite reading many supposed solutions.

 

Basically I maintain the site http://www.thebasementyork.co.uk which is PHP driven and based on a MySQL database. Some of the pages are generated including an image file the (relative) pathname of which is stored as one of the fields in the database. This all works fine and the pages display as they should.

 

However, I've been building a backend to help me spot problems occuring in the database. One of these test to see if the pathname points to a file that exists, as such:

 

$result = mysql_query( "SELECT EventID, EventName, EventStart, PosterURL FROM eventstable ORDER BY EventStart ASC" );
while ( $row = mysql_fetch_array( $result ) ) {
	if ( !file_exists( $_SERVER['DOCUMENT_ROOT'].$row['PosterURL'] ) && isset( $row['PosterURL'] ) ) {
		/* echo details of the entry that needs correcting */
	}
}

 

This works fine for all files in the posters folder apart from those in a subfolder that is used to store posters that are used for multiple events (due to the file naming rules I use). This is for events such as this one (http://www.thebasementyork.co.uk/event/29/) - which displays the poster even though PHP is telling me it doesn't exist.

 

It doesn't seem to be a permissions issue as I've granted maximum permissions for the subfolder.

 

Any suggestions?

Link to comment
Share on other sites

Thanks for the suggestion, but all var_dump returns is:

 

string(47) "/event-posters/regulars/takethestageposter.jpg "

string(26) "/home/thebasem/public_html"

 

Which is what I would have expected so doesn't really help.

 

Any other ideas?

 

Are you 100% sure they fit together?

$_SERVER['DOCUMENT_ROOT'].$row['PosterURL']

 

Try checking the result of:

echo= '/home/thebasem/public_html' . $row['PosterURL'];

 

It may be possible the path is not completely correct, such as a missing forward slash. This would cause file_exist to return a false, as you could imagine. Only thing I can think of right now.

Link to comment
Share on other sites

string(47) "/event-posters/regulars/takethestageposter.jpg "

 

As PFMaBiSmAd said, there is a space character at the end of this string which (I'll make an educated guess here) should not be there. Change the value in the database to not have that space and that should be your issue solved. It's probably worth making sure no extra spaces are appended/prepended to paths when inserting them into the database initially.

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.