Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted

What is $latestNewsletter exactly?

edit: sorry, wrong informaton. try this instead: $latestNewsletter->filename

  • Thanks 1
Posted

I edited the previous answer, here goes again in case you didn't see

$latestNewsletter->filename

Posted

Okay, I got it.

So now I have

if(file_exists($latestNewsletter->filename))

{

?><a href="<?= $latestNewsletter->url; ?>">text</a><?php

}

Thanks for the help :)

Posted

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.

Posted

I will check out the cheatsheet.

Your code example is cleaner. I will copy this style from now on.

Thanks again.

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
  • Recently Browsing   0 members

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