Solved

fopen opening remote files but not local ones

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now