Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading mailbox from php 1

Status
Not open for further replies.

elck

Programmer
Apr 19, 2004
176
NL
Suppose my mailbox is in
/usr/domain/mail/inbox

Of course I cannot read it like this:

$a=file("/usr/domain/mail/inbox");

because the mail directory is outside of the html range.

I know very little about unix, but could I call a batchfile from php in a cgi-bin that p.e. copies the inbox to a place where php can read it?

Or can you think of an other solution?
 
I'm not sure what you mean by "outside of the html range", but PHP's filesystem functions are not constrained by the web site's document root. Unless constrained by a custom PHP configuration or by filesystem permissions, you can open any file on the filesystem.


However, on unix-like OSes, mailboxes are stored two ways, one is as a single-file database (called an "mbox") or as a directory hierarchy (called a "maildir").




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
You are right in so far as the p.e. upload directory is concerned. Yet when I try, as described above to open the inbox file with $a=file("/usr/domain/mail/inbox"); I get a permission denied error.

With ftp I can see that such a file exists.

I even chmod that file to 777.

So you think it is a php configuration problem?
 
No. It's a permissions problem. Your web server will run as a user, but chances are that's not the same user you use to login via FTP. Your web server's username does not have permission to the directory or file.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ok I understand that.
Now can I use a perl or c script from a cgi-bin or through a cgiwrapper that does have that permission and copy the file to a place where I can access it?
Or maybe a cron job?

Or is this beyond the scope of this forum?
 
If you're talking about a c-language compiled program or a perl script, yes, your out of topic. But cron will run PHP scripts just as well as it will perl scripts.

A PHP script run by cron could, I suppose, copy your mailbox to a convenient directory and set permissions on it such that your web server's user can access it.


How much control do you have over the system on which you're trying to do this? You might consider tweaking permissions on the filesystem -- perhaps create a group to which your web server's user is a member, then set group ownership on the mailbox to that group.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I cannot control the filesystem other then through chmod.

But if I run a php script through cron is it possible that it has other permissions, maybe the same as when i ftp?

Does it have to be in a cgi-bin or can it reside anywhere?

Sorry many questions.
 
Everything in your crontab should run as your user, so if you make the changes to crontab as the same user as which you FTP, it should work.

A cron script can reside anywhere, but remember your shebang notation at the beginning of the file:

#! /path/to/php
<?php
//script begins
?>


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Right, thanks a lot Sleipnir
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top