1

I am trying to create php file using codeigniter, I want to create that file inside views folder or inside controller/ model dynamically. But I am getting error Message: fopen(application/views): failed to open stream: No such file or directory. Looks like kind of restriction from codeigniter. How can I achieve this task ?

My Code:

        $file_location = APPPATH . "views"; 

        $myfile = fopen($file_location, "newfile.php", "w") or die("Unable to open file!");
        $txt = "<?php\n ";  
        $txt .= "echo 'something';\n" ;
        $txt .= "?>\n ";

        fwrite($myfile, $txt);
        fclose($myfile);

1 Answer 1

1

No this is a PHP issue I believe, not a code igniter.
See this line here:
fopen($file_location, "newfile.php", "w")

From the docs:
resource fopen ( string $filename , string $mode [, bool $use_include_path = FALSE [, resource $context ]] )

So change your fopen too:
fopen($file_location. "newfile.php", "w")
(I changed the , to a . to construct the file path)

Edit: make sure your $file_location ends with a / or add one to the start of newfile.php

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.