gnome Posted October 8, 2012 Posted October 8, 2012 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?
diogo Posted October 8, 2012 Posted October 8, 2012 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.
gnome Posted October 8, 2012 Author Posted October 8, 2012 Thanks, but if I echo $latestNewsletter->path I get nothing.
diogo Posted October 8, 2012 Posted October 8, 2012 What is $latestNewsletter exactly? edit: sorry, wrong informaton. try this instead: $latestNewsletter->filename 1
gnome Posted October 8, 2012 Author Posted October 8, 2012 $page->latestNewsletter latestNewsletter is a file field.
diogo Posted October 8, 2012 Posted October 8, 2012 I edited the previous answer, here goes again in case you didn't see $latestNewsletter->filename
gnome Posted October 8, 2012 Author Posted October 8, 2012 Okay, I got it. So now I have if(file_exists($latestNewsletter->filename)) { ?><a href="<?= $latestNewsletter->url; ?>">text</a><?php } Thanks for the help
diogo Posted October 8, 2012 Posted October 8, 2012 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.
gnome Posted October 8, 2012 Author Posted October 8, 2012 I will check out the cheatsheet. Your code example is cleaner. I will copy this style from now on. Thanks again.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now