• Status: Solved
• Priority: Medium
• Security: Public
• Views: 437

# List remote files

Hi Experts!

I'm developing an intranet application in PHP that performs a file conversion (XLS to PDF); it lists all the XLS files of a given input folder and saves them as PDF inside a given output folder.

I'l like to be able to specify a network path (such as "\\computer\c$\input") so that my application could list and convert XLS files from folders located even on the users' pcs and save them as PDF the same way (such as "\\computer\c$\output\filename.pdf")... is this possible?

I have Administrator rights so that, if needed, I can set some permissions on those remote folders.

Kupi
0
Kupi
• 6
• 4
• 2
1 Solution

Commented:
Yep, that's certainly possible.  We have a similar situation in our company currently, and we're accessing remote files in that manner.

If you're running IIS, you need to make sure that the user that IIS runs under has the appropriate network privileges (admin, in this case) to work on the files in question.  This could pose a notable security risk, so make sure that your intranet application *stays* intranet, if you know what I mean.  You might also want to take other precautions to ensure that you're protected.

If you're running Apache server, you need to change the user that the service runs as.  You can do so in the Services console (Start -> Control Panel -> Administrative Tools -> Services).  Right-click on Apache and go to Properties.  Go to the "Log on" tab, and set the user to a valid network user.  In my company, we've setup a specific domain user just for this purpose.  Restart Apache server, and it should work nicely.  There's a more complete set of instructions here:  http://httpd.apache.org/docs-2.0/platform/windows.html#winsvc

In PHP, you can access your resources in the way you mentioned above.  For example:  fopen("\\computer\share\path\to\file", "w+");

Hope that helps,
-Doug
0

Author Commented:
Thank you dougday!

I see fopen opens a remote file, but what if I need to access a remote folder and list its files?
0

Commented:
If the folders do not have a default index page, then you can fopen the folders I believe. If they do, then the only thing I can think of is if you have ftp access so you can find the files.
0

Author Commented:
My input folder doesn't have web pages in it, just XLS files... so I should be able to list them!

Can someone post an example of using fopen to list files of a given folder? I keep getting a "failed to open stream: Permission denied" error while attempting to do that...

And still cannot use network paths (\\computer), just locals (c:\\)... any help would be very appreciated!
0

Commented:
Hmm... Try to chmod your folder to 777
0

Author Commented:
I'm running Windows XP (PHP 4.3.7 + IIS 6) and I've set the full control right to Everyone...
0

Commented:
You don't use fopen() to list files in a remote folder.  That's probably why you're getting a permission denied error.

Try the glob() function instead.  http://us4.php.net/manual/en/function.glob.php
It returns an array of files that match a pattern.

For example:

$files = glob("\\\\computer\\share\\path\\to\\folder\\*.xls"); foreach($files as $file) { echo$file . "\n";
}

Would result in an output similar to this:

\\computer\share\path\to\folder\file1.xls
\\computer\share\path\to\folder\file2.xls
\\computer\share\path\to\folder\file3.xls

Hope that helps.  Let me know if you have any more questions :)
-Doug
0

Commented:
Actually, I forgot to use is_array() also to make sure that glob() returned some files.  Here's a better example:

$files = glob("\\\\computer\\share\\path\\to\\folder\\*.xls"); if (is_array($files)) {
foreach($files as$file) {
echo \$file . "\n";
}
}
0

Commented:
Kupi, sometimes the "Everyone" group doesn't behave as you'd expect.  I'm not positive that non-user accounts are included in that group (like the IIS user IUSR_***).  If you still have directory permission problems, you might want to create a domain account that your IIS can run as.  I don't think the IUSR_*** account can access network resources anyway (I could be wrong).  So, create an account just for IIS, and change your username in IIS.

To do so, right-click on your web site in IIS -> Properties -> Directory Security -> Edit Authentication Methods for Resource -> Edit Account Used for Anonymous Access.

-Doug
0

Commented:
Thanks for the A.  :)  Hope that helped.
-Doug
0

Author Commented:
dougday,
when I try to use fopen with network paths I get:

Warning: fopen(\\computer\shared_folder\file_name.xls): failed to open stream: Invalid argument

Even the glob function doesn't work...

The strange thing is that everything works fine if client and server are the same machine, so I think it's a permissions issue... I tried setting the full control right to Everyone and Domain Users but nothing changes...

Can you give me a step-by-step explaination of how to create the needed users/groups and set the appropriate rights?

0

Commented:
First create a domain user for your IIS.  Here's a brief tutorial:  http://www.ucertify.com/articles/70-218/2101022.html.

Then, log in as that user and make sure you have access to the resources in question.  If you have permission issues, you should be able to resolve them by logging on as an administrative user, allowing access to the resources, then logging on as the user you created and testing it.  If you need a tutorial on this, there are several out there on the web.  Just search for "NTFS Permissions".

Also, if your IIS server uses Integrated Windows Authentication for Directory Security, you'll need to make sure each user has *normal* access to that .xls file -- they can get to it using Windows Explorer.

Once you're sure your user can access your resources, then right-click on your web site in IIS and click Properties -> Directory Security -> Edit Authentication Methods for Resource -> Edit Account Used for Anonymous Access.  Then change the user that IIS uses to the one you created.

Hope that helps,
-Doug
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.