dmccabe Posted August 15, 2008 Share Posted August 15, 2008 Yet another "not working as expected" thread from me. I have an online list of all the branches at work, for some of these branches we have document detailing local directions to the site so they can print them out and give them customers. However not all branches have this document, so I was trying to make it the list would check if the file exists, if so let them open it, if not then display a "no local directions" message. code is like this at the moment: $filename = "//serverfile/general/Procedure%20Manual/1.0%20usefull%20information/branch%20directions/$dirname.doc"; echo $filename; echo "</td> if (file_exists($filename)) { echo "<strong><a href='file://serverfile/general/Procedure%20Manual/1.0%20usefull%20information/branch%20directions/$dirname.doc' title='Click to view local directions for branch'>(Local Directions)</a></strong>"; } else { echo "(No Local Directions)"; } Edit: Sorry currently all branches are coming up as "No Local Directions" and the $dirname is correct I have double checked that part. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/119818-file_exists-not-working-as-expected/ Share on other sites More sharing options...
willsavin Posted August 15, 2008 Share Posted August 15, 2008 is this just been typed quickly? echo $filename; echo "</td> there is a " and a semicolon missing at the end of this echo.. Quote Link to comment https://forums.phpfreaks.com/topic/119818-file_exists-not-working-as-expected/#findComment-617294 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 This does not look correct. You have URL encoded values in the file path $filename = "//serverfile/general/Procedure%20Manual/1.0%20usefull%20information/branch%20directions/$dirname.doc"; Use proper directory naming conventions: $filename = "/var/www/html/manuals/procedures/mydocumentname.doc"; No spaces in directory names/filenames. No urlencoded string i.e. %20 Quote Link to comment https://forums.phpfreaks.com/topic/119818-file_exists-not-working-as-expected/#findComment-617297 Share on other sites More sharing options...
dmccabe Posted August 15, 2008 Author Share Posted August 15, 2008 This is a problem then as it is checking a file on another server within a share, I cant change the name of the directory as it is used for my other things too. THe php manual says you can use share names like \\server\share. http://uk3.php.net/function.file-exists Path to the file or directory. On windows, use //computername/share/filename or \\computername\share\filename to check files on network shares. Quote Link to comment https://forums.phpfreaks.com/topic/119818-file_exists-not-working-as-expected/#findComment-617326 Share on other sites More sharing options...
ajclarkson Posted August 15, 2008 Share Posted August 15, 2008 I believe neil was referring to the use of filenames such as Procedure%20Manual rather than the actual \\server\share bit. It is ok to do network share filepaths, but you can often get problems where encoded characters come into the string. In your case Procedure Manual is transformed to Procedure%20Manual which has implications on systems using different methods of character encoding. Is it possible at all to rename the folders? Quote Link to comment https://forums.phpfreaks.com/topic/119818-file_exists-not-working-as-expected/#findComment-617327 Share on other sites More sharing options...
dmccabe Posted August 15, 2008 Author Share Posted August 15, 2008 Unfortunately not, the "branch directions" part can be renamed, but not the "1.0 Usefull Information" or "Procedure Manual" as these heavy shared and access from all over the company. Is there a way round this? Quote Link to comment https://forums.phpfreaks.com/topic/119818-file_exists-not-working-as-expected/#findComment-617335 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 Your other option is to use a flag field in your database table. You could use an ENUM(1,2) If the branch has a document, set the field value to 2 else have it default to 1. Then you can easily check this value in a condition to display an image link or not. Quote Link to comment https://forums.phpfreaks.com/topic/119818-file_exists-not-working-as-expected/#findComment-617398 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.