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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot open a file

Status
Not open for further replies.

xtreemnet

Programmer
Joined
Aug 9, 2003
Messages
88
Location
NZ
Hi

I am new to PHP. I am trying to open a file using "fopen", but its not working. following is the code I am using:

<html>
<?php
$filename = 'chees.doc';
$fp = fopen($filename, "r");

if(!$fp) {
echo "Cannot open file ($filename)";
return -1;
}
echo "Opened file ($filename)";
fclose ($fp);
?>
</html>

This works when run from local machine. but when its uploaded on the web site, it says "Cannot open file (chees.doc)".
This is such a simple code, but I do not understand what's wrong.

Thanks,
 
1) Does the user running PHP (usually 'nobody') have read access to chees.doc? Try chmod 0644 chees.doc.

2) Does chees.doc exist on the host running PHP? (I had to ask)

Check on these things. I'm 99% sure that one of these is the problem.

Glad to help.
Will
 
chees.doc exists in the directory where the php file is. I will try the chmod.

Please note that by mistake this post was created twice. so please reply to the other one next time.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top