0

I am trying to create a PHP file in a directory,but its not creating. Here is my code:

function createPage(){ $name='test'; $file=base_url()."test/".$name.".php"; $handle = fopen($file, 'w') or die('Cannot open file: '.$file); } 

This shows me:

failed to open stream HTTP wrapper does not support writable connections error. 

Can anyone fix this problem? I am new in PHP file handling.

5
  • Is this localhost? because stream errors are generally related to an apache configuration that doesn't allow them. It could also be because you're using base_url() which likely includes an absolute path, such as, http://localhost/path/to/my/files/, which will throw the error. Simply supply a relative path. Commented May 24, 2013 at 17:53
  • You should take a look at CI's file helper. It's much easier than doing everything yourself. Commented May 24, 2013 at 17:59
  • apache's user usually is not allowed to create files Commented May 24, 2013 at 17:59
  • one dirty solution would be give 777 permission to the test folder Commented May 24, 2013 at 18:00
  • don't use base_url() with file. Commented May 25, 2013 at 3:55

1 Answer 1

2

I won't discuss the security implications of having your php directory writable, but I'm fairly sure you're not intending to create the directory using an URL;

(base_url() returns something like http://mysite.com/ci/)

What you probably want to use is a local file system path, something like this should help;

$file = FCPATH."/test/".$name.".php"; 

...which will create a file in the test sub directory of the directory where your codeigniter index.php resides.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.