Current location: Hot Scripts Forums » Programming Languages » PHP » Check If File exists on network


Check If File exists on network

Reply
  #1 (permalink)  
Old 06-14-07, 03:43 PM
mattdc2001's Avatar
mattdc2001 mattdc2001 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: North Carolina
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Check If File exists on network

Hi! I am trying to make a script that will check to see if a file exists on my local network.

PHP Manual says for file_exists(): On windows, use //computername/share/filename or \\computername\share\filename to check files on network shares.

So I came up with this:
PHP Code:

<?php

$file 
"//Gobigmusic/SharedDocs/hello.txt";

if ( 
file_exists($file) ){
echo 
"I CAN SEE IT!!!!!";
} else {
echo 
"I can't see it yet.";
}
?>
It keeps telling me it can't see it

Any Ideas?
Reply With Quote
  #2 (permalink)  
Old 06-14-07, 03:59 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Either check your web server log for errors or put the following two lines in after your first opening <?php tag to get PHP to tell you of any errors that it is detecting -
PHP Code:

ini_set ("display_errors""1");

error_reporting(E_ALL); 
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 06-14-07, 04:21 PM
mattdc2001's Avatar
mattdc2001 mattdc2001 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: North Carolina
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
I put in the two lines and I am receiving no errors.
Reply With Quote
  #4 (permalink)  
Old 06-14-07, 04:30 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I'm not sure if file_exists() would throw an error in any case. And if you try opening the file with fopen() in r mode?
Reply With Quote
  #5 (permalink)  
Old 06-14-07, 04:42 PM
mattdc2001's Avatar
mattdc2001 mattdc2001 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: North Carolina
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Hrm, that gives some more information to work with. I tried:

PHP Code:

<?php

ini_set 
("display_errors""1");
error_reporting(E_ALL); 

$file "//Gobigmusic/SharedDocs/hello.txt";
fopen($file"r");

?>
and got:
Warning: fopen(//Gobigmusic/SharedDocs/hello.txt) [function.fopen]: failed to open stream: Permission denied in E:\Websites\localwww\file.php on line 6
__________________
Andrei, you've lost another submarine?
Reply With Quote
  #6 (permalink)  
Old 06-14-07, 04:51 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Are you able to access the file via "my network places"? Did you try using backslashes instead?

PHP Code:

$file "\\\\Gobigmusic\\SharedDocs\\hello.txt"
Reply With Quote
  #7 (permalink)  
Old 06-14-07, 04:56 PM
mattdc2001's Avatar
mattdc2001 mattdc2001 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: North Carolina
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Nico View Post
Are you able to access the file via "my network places"? Did you try using backslashes instead?
I can access it through My Network Places just fine and I did try backslash and got the same error message.
__________________
Andrei, you've lost another submarine?
Reply With Quote
  #8 (permalink)  
Old 06-14-07, 05:11 PM
mattdc2001's Avatar
mattdc2001 mattdc2001 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: North Carolina
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
I just did a Map Network Drive to map \\Gobigmusic\SharedDocs to Z:\ and ran:
PHP Code:

<?php
ini_set 
("display_errors""1");
error_reporting(E_ALL); 

$file "Z:/hello.txt";
fopen($file"r");

?>
and got:
Warning: fopen(Z:/hello.txt) [function.fopen]: failed to open stream: No such file or directory in E:\Websites\localwww\file.php on line 6

But it most defiantly is. Like I said, I can see it and open it in explorer just fine.
__________________
Andrei, you've lost another submarine?
Reply With Quote
  #9 (permalink)  
Old 06-15-07, 02:36 PM
mattdc2001's Avatar
mattdc2001 mattdc2001 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: North Carolina
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
I don't suppose anybody else has some idea or even another way to accomplish what I'm tying to do?
__________________
Andrei, you've lost another submarine?

Last edited by mattdc2001; 06-15-07 at 02:41 PM. Reason: I'm sorry, I didn't mean to bump. I wasn't paying attention.
Reply With Quote
  #10 (permalink)  
Old 06-15-07, 03:58 PM
soloWebDev soloWebDev is offline
Wannabe Coder
 
Join Date: Apr 2007
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$myfile "SharedDocs\hello.txt"
$file "\\Gobigmusic\SharedDocs\hello.txt"
if (
file_exists($file)){ 
echo 
"I CAN SEE IT!!!!!"
} else { 
echo 
"I can't see it yet."

White space and your slashes were the wrong direction. give this a shot.
this worked for me $myfile (example above)
Also make sure if start to add variables to your url or page, to change the direction of the slashes. (example below)
foo\foo2/$bar/$bar2
__________________
We will see what happens next.

Last edited by soloWebDev; 06-15-07 at 04:00 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Check uploaded file type. jumbo1 PHP 10 02-25-07 01:43 PM
file exists in flash tamil Flash & ActionScript 0 10-12-06 07:30 AM
Error message not getting displayed. sanjeet Windows .NET Programming 0 12-20-05 10:48 AM
[SOLVED] check if directory exists lordy PHP 2 07-04-05 01:17 AM
how to check if a file exists in the include path wizkid PHP 2 01-04-05 06:47 PM


All times are GMT -5. The time now is 06:03 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.