?
Solved

fopen opening remote files but not local ones

Posted on 2004-08-26
4
Medium Priority
?
400 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 400 total points
ID: 11909185
try

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

Assisted Solution

by:Umesh
Umesh earned 400 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 1200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

839 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