Jump to content

file_exists


gnome
 Share

Recommended Posts

Hi

I am using file_exists to see if a PDF file exists on the server:

if(file_exists($latestNewsletter->url))

{

// link to pdf

}

but this is returning false.

The file definitely exists. If I change to !file_exists, the link is shown and links to the PDF correctly.

Does anyone know why this is happening?

Link to comment
Share on other sites

The url dosen't tell the server where the file is. You have to use path.

Edit: I wasn't explicit. When I mean path, I'm talking about the path on the server. You can use $latestNewsletter->path, when $latestNewsletter refers to a file.

Link to comment
Share on other sites

Two more things:

Do you know the cheatsheet? It's an invaluable resourse, all these things are there http://processwire.com/api/cheatsheet/

Concerning your code, you can do the same like this:

if(file_exists($latestNewsletter->filename))
{
  echo "<a href='{$latestNewsletter->url}'>text</a>";
}

All depends on each one's style, and it's perfectly ok, but I think this one is cleaner.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...