Solved

fopen opening remote files but not local ones

Posted on 2004-08-26
4
393 Views
Last Modified: 2006-11-17
Hello.

I am trying to use fopen to open a local file.

    $fp = fopen("/home/mysite/public_html/pages/test.php", 'r');

does not work

    $fp = fopen("/home/mysite/public_html/pages/test.php", 'r');

does not work either


But, if I put it as a web address it works:
    $fp = fopen("http://www.mysite.com/pages/test.php", 'r');
      

How can I get this to open my local file without having to use http?

Here is my code.

Thanks!

    <?php
    $fp = fopen("http://www.mysite.com/pages/test.php", 'r');
    if (stream_set_timeout($fp, 15) == false){
                echo "Error: Could Not Connect";
        fclose($fp);
    }
    elseif (!$fp){
                echo "Error: Could Not Connect";
        fclose($fp);
    }
    else{
     @fgets($fp);
    fclose($fp);
    }
    ?>
0
Comment
Question by:hankknight
4 Comments
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 100 total points
ID: 11909185
try

$fp = fopen($_SERVER['DOCUMENT_ROOT']."/pages/test.php", 'r');
0
 
LVL 26

Assisted Solution

by:ushastry
ushastry earned 100 total points
ID: 11911238

Hi,

Check this url..

http://us2.php.net/fopen


Hope this helps!
0
 
LVL 25

Accepted Solution

by:
Marcus Bointon earned 300 total points
ID: 11911456
D84's suggestion will probably work, but only by forcing you to put your files somewhere else. It may not be possible to access your files where they are, depending on your OS - for example OpenBSD runs apache chrooted to /var/www, so as far as the web server is concerned, /home does not exist. If the connection to your local folder fails, it would be a good idea to increase your error reporting level (e.g error_reporting(E_ALL), to see if it's something like 'directory not found'  or 'permission denied'. Then you have some way of knowing whether it's a simple permissions problem or something else.
0
 
LVL 16

Author Comment

by:hankknight
ID: 11912794
Aggggg!  Those aliases!  The log helped me to identify the propor path.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question