Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3317804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:37:49+00:00 2026-05-17T22:37:49+00:00

Short story: I’m getting an open_basedir restriction in my php script – a simple

  • 0

Short story:

I’m getting an open_basedir restriction in my php script – a simple “test writing a new file to disk” script. It SEEMS to me that I’ve got the open_basedir settings correct and the file is in the right location – but no luck, just the same error every time. I’ve searched for similar open_basedir problems on this site, but I’ve not seen any with this problem – where the directory looks right but it still throws errors.

My guesses as to what the problem is:
1) open_basedir doesn’t work the way I think it does
2) My settings are wrong and I’m just not seeing it
3) It’s actually something else, like IIS read/write permissions, etc
4) ???

Long story:

I’m working on an IIS server with PHP and I’m trying to get the following code snippet to work (a simple write file test):

date_default_timezone_set('America/Chicago');
$myFile = 'testfile.txt';
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Some Text\n";
fwrite($fh, $stringData);
$stringData = "Some More Text\n";
fwrite($fh, $stringData);
fclose($fh);

This php script is located at C:\inetpub\wwwroot\WEBDIRECTORY\test_write.php on my server

Here is my php.ini setting for open_basedir:
open_basedir = c:\inetpub\wwwroot;c:\inetpub\wwwroot\WEBDIRECTORY

Whenever I open the script’s page, I am expecting to see no output, and then there should be a new file written on the server when I check back. This is what I get instead:

Warning: fopen(): open_basedir
restriction in effect.
File(testfile.txt) is not within the
allowed path(s): (c:\inetpub\wwwroot)
in
C:\inetpub\wwwroot\WEBDIRECTORY\test_write.php
on line 5 Warning:
fopen(testfile.txt): failed to open
stream: Operation not permitted in
C:\inetpub\wwwroot\WEBDIRECTORY\test_write.php
on line 5 can’t open file

I’ve tried a lot of permutations: originally the open_basedir line was just
open_basedir = c:\inetpub\wwwroot

…but that didn’t work, either.

I’ve also tried entering an absolute path for testfile.txt (c:\inetpub\wwwroot\WEBDIRECTORY\testfile.txt, etc) instead of just the name of the file itself, and I keep getting the same error message.

Any ideas? Thanks so much for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:37:49+00:00Added an answer on May 17, 2026 at 10:37 pm

    Okay, so sorry to waste everyone’s time – turns out it was a server setting my system administrator had set for me. (I’m new to this so I’ll explain in general terms that I understand)

    He’d set it up so that the server would not resolve an address for any files in the web directory except certain types you expect to find on a website, such as .htm, .html, .php, .jpg, etc. The file I was trying to read was .txt.

    So, I wrote some test code:

    $test = realpath('c:\inetpub\wwwroot\WEBDIRECTORY\testfile.php');
    echo ("test = $test\n");
    if($test == FALSE){
     echo ("... is FALSE\n");
    }
    
    $test = realpath('c:\inetpub\wwwroot\WEBDIRECTORY\testfile.txt');
    echo ("test = $test\n");
    if($test == FALSE){
     echo ("... is FALSE\n");
    }
    

    Which promptly returned this:

    test = C:\inetpub\wwwroot\WEBDIRECTORY\testfile.php
    test = … is FALSE

    So, realpath is refusing to return an address for anything ending in .txt, but is more than happy to do that for a .php file. This means that WHENEVER I put in an otherwise legal (within the basedir) filename that ends in an illegal extension, the server resolves that address not as “C:\inetpub\wwwroot\WEBDIRECTORY\testfile.txt” but as “”. And of course, an empty string is not going to be in the basedir, returning open_basedir restriction errors.

    BIZARRE! But makes sense now that I finally traced it back to its source. Thanks for all the tips! It helped me go through process of elimination and figure this one out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Cut a short story even shorter, Have a asp.net page with MaintainScrollPositionOnPostback=true in the
Long story short, I have a substantial Python application that, among other things, does
To make a long story short I have to use processing in a class
Short of putting a UIWebView as the back-most layer in my nib file, how
Short version: I want to trigger the Form_Load() event without making the form visible.
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific
Short of cutting and pasting, is there a way to sort the methods in
Short: how does modelbinding pass objects from view to controller? Long: First, based on
Short version: assuming I don't want to keep the data for long, how do
Is there drop-in replacement for ActiveRecord that uses some sort of Object Store? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.