Solved

fopen opening remote files but not local ones

Posted on 2004-08-26
4
394 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: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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 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