Learn how to a build a cloud-first strategyRegister Now

x
Solved

# List remote files

Posted on 2005-05-10
Medium Priority
435 Views
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
Question by:Kupi
• 6
• 4
• 2

LVL 5

Expert Comment

ID: 13971050
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

LVL 3

Author Comment

ID: 13975418
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

LVL 36

Expert Comment

ID: 13976381
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

LVL 3

Author Comment

ID: 13976503
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

LVL 36

Expert Comment

ID: 13976528
Hmm... Try to chmod your folder to 777
0

LVL 3

Author Comment

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

LVL 5

Expert Comment

ID: 13978140
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

LVL 5

Accepted Solution

dougday earned 500 total points
ID: 13978163
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

LVL 5

Expert Comment

ID: 13978339
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

LVL 5

Expert Comment

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

LVL 3

Author Comment

ID: 13984484
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

LVL 5

Expert Comment

ID: 13987121
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
###### Suggested Courses
Course of the Month20 days, 17 hours left to enroll