如何在代码点火器中的视图文件夹中创建文件



我正在尝试使用codeigniter创建php文件,我想在视图文件夹内或控制器/模型内动态创建该文件。但是我Message: fopen(application/views): failed to open stream: No such file or directory收到错误.看起来像是codeigniter的限制.我怎样才能完成这个任务?

我的代码:

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

不,我相信这是一个PHP问题,而不是代码点火器。
请参阅此处的这一行:
fopen($file_location, "newfile.php", "w")

从文档中:
resource fopen ( string $filename , string $mode [, bool $use_include_path = FALSE [, resource $context ]] )

所以也改变你的 fopen:
fopen($file_location. "newfile.php", "w")
(我将 , 更改为 . 以构造文件路径(

编辑:确保您的$file_location/结尾,或在newfile.php的开头添加一个

最新更新