file_exists() works on one server, but not on another
Posted: Wed Jun 18, 2008 4:20 pm
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';
}
}
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';
}
}