Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/119818-file_exists-not-working-as-expected/
Share on other sites

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

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.

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.