gnome Posted October 8, 2012 Share 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? Link to comment Share on other sites More sharing options...
diogo Posted October 8, 2012 Share 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. Link to comment Share on other sites More sharing options...
gnome Posted October 8, 2012 Author Share Posted October 8, 2012 Thanks, but if I echo $latestNewsletter->path I get nothing. Link to comment Share on other sites More sharing options...
diogo Posted October 8, 2012 Share Posted October 8, 2012 What is $latestNewsletter exactly? edit: sorry, wrong informaton. try this instead: $latestNewsletter->filename 1 Link to comment Share on other sites More sharing options...
gnome Posted October 8, 2012 Author Share Posted October 8, 2012 $page->latestNewsletter latestNewsletter is a file field. Link to comment Share on other sites More sharing options...
diogo Posted October 8, 2012 Share Posted October 8, 2012 I edited the previous answer, here goes again in case you didn't see $latestNewsletter->filename Link to comment Share on other sites More sharing options...
gnome Posted October 8, 2012 Author Share 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 Link to comment Share on other sites More sharing options...
diogo Posted October 8, 2012 Share 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. Link to comment Share on other sites More sharing options...
gnome Posted October 8, 2012 Author Share 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. Link to comment Share on other sites More sharing options...
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