-2
class File extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->helper('file');
    }

    function writetest()
    {
        $data = "Hello World!";
        $file= "application.DIRECTORY_SEPERATOR.test_data.DIRECTORY_SEPERATOR.helloworld.txt";
        $write_file($file,$data);
        echo "finished writing";
    }

This code shows the following error message in CodeIgniter:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: Write_file

Filename: controllers/file.php

Line Number: 18

Fatal error: Function name must be a string in /var/www/html/fazrin/application/controllers/file.php on line 18

This is line 18:

 $write_file($file,$data);
Kirk Beard
  • 8,124
  • 12
  • 39
  • 43

2 Answers2

2

$write_file is not variable it is a function of Codeigniter .You are treating the write_file() as varibable. So, you must remove $ in '$write_file($file,$data) as below :

function __construct()
   {
        parent::__construct();
        $this->load->helper('file');
    }

    function writetest()
    {
        $data = "Hello World!";
        $file= "application.DIRECTORY_SEPERATOR.test_data.DIRECTORY_SEPERATOR.helloworld.txt";
       write_file($file,$data);
        echo "finished writing";
    }
Drudge Rajen
  • 5,431
  • 4
  • 19
  • 41
0

Can't use $ in front of write_file($file,$data)

Domain
  • 10,694
  • 2
  • 19
  • 41