Solved

fopen opening remote files but not local ones

Posted on 2004-08-26
4
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Umesh
Umesh 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

717 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