Page 1 of 1

file_exists() works on one server, but not on another

Posted: Wed Jun 18, 2008 4:20 pm
by npurcell
Hello -

I am working on an intranet webpage which uses a script I wrote in PHP to add wildcards onto the end of base filenames (to indicate the latest rev; e.g. 100400RB.doc) located on another server. The script goes through an array consisting of the alphabet backwards and when file_exists() indicates TRUE, returns the filename. The reason it goes through backwards is that there could be more than one rev in the directory (e.g. 100400RA.doc and 100400RB.doc) and I'd like to get the most recent one.

Here is how I am using it in my webpage:
<?php $filename = get_latest_rev("100400.doc"); ?><a href="<?php echo $filename; ?>" target="_blank

I first do my developing on my own pc, then move it to the web server where the website is located (the documents are on a third server). For some reason, after I move the code over to the web server, the script never returns TRUE. The script works just fine on my own system. I read online somewhere that file_exists() doesn't work over the network, but from the web server I can see the document server using the exact same path I do from my pc (\\doc_server\documents\). I've tried fopen() and and is_file() with similar results. The document server doesn't ask users to login, anyone on the network is able to see it.

Has anyone ever had or heard of this problem? Thanks in advance!

Npurcell

ps Here is the script

<?php
function get_latest_rev($doc_name)
{
$rev_exists = false;
// take apart $doc_name and add letter to it
$ext = strrchr($doc_name,".");
$len = strlen($doc_name) - 4;
$doc_name = substr($doc_name,0,$len);
$fileLocation = "file://///Holocron/p&v documents/"; // \\Holocron\p&v documents\ is doc server name
// $letter variable
$test_letter = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

for($i=25;$i>=0;$i--)
{
// append $letter to $doc_name and put it back together
$search_doc = $p_v_directory.$doc_name."R".$test_letter[$i].$ext;

// see if file_exists
$rev_exists = file_exists($search_doc);

if($rev_exists)
{
return $fileLocation.$doc_name."R".$test_letter[$i].$ext;
}
// keep track of which letter we get (also could be no letter)
}
// test for document without rev letter
$search_doc = $p_v_directory.$doc_name.$ext;
$doc_exists = file_exists($search_doc);

if($doc_exists)
{
return $fileLocation.$doc_name.$ext;
}
else
{
return 'not found';
}
}

Re: file_exists() works on one server, but not on another

Posted: Wed Jun 18, 2008 7:45 pm
by LSJason
Are you running PHP 4 or 5 on your server and PC, respectively? There are some integral differences in the way each processes file_exists() commands (and other file*() commands):

In PHP 4.x, all file operations assume the local file system
(effectively, "file://" is prepended to the given filename before
operating on it.) The workaround is to use drive letters instead.

In PHP 5.x, you can work with UNC shares BUT there are caveats: (1)
from the manual "...this function returns FALSE for files inaccessible
due to safe mode restrictions." and (2), note this comment about
running under domain accounts:
<http://aspn.activestate.com/ASPN/Mail/M ... oc/1183917> Check
permissions for the folder and file are appropriate for the web server
account.

Re: file_exists() works on one server, but not on another

Posted: Thu Jun 19, 2008 11:29 am
by npurcell
Jason, thank you so much for your reply! Our IT person is going to implement the change and then I can see if that fixes it.

Thanks again!

Re: file_exists() works on one server, but not on another

Posted: Fri Jun 27, 2008 5:43 pm
by npurcell
Hi again -

We checked our settings but still can't get the script to work. One question: our web server and file server are on 2 different machines; would we need php on the file server as well as the web server?

thanks in advance!

Re: file_exists() works on one server, but not on another

Posted: Fri Jun 27, 2008 5:55 pm
by LSJason
So, you're 100% sure that your PC and webserver run the same version of PHP (check using "php -v" (no quotes) on both machines)?

My next guess would be some sort of authentication thing (transparent authentication by the file server box--or just trans-OS issues).

Re: file_exists() works on one server, but not on another

Posted: Fri Jun 27, 2008 5:59 pm
by npurcell
Yes, 5.2.5, same build date.

Thanks Jason - I'll pass on your suggestion to our IT guy. Appreciate your response!