Baris
Baris

Reputation: 59

How to write a text to a txt file (codeigniter)

After I had checked the questions here, I saw that I need write_file for text writing to a .txt file. I also looked for a tutorial or an example about it on Google but couldn't find a simple one.

Could you explain me basically about how to write something to a .txt file in Codeigniter?

As an example, a text is submitted by a user on a registration form and then the text written by the user, will be shown in users.txt.

Upvotes: 1

Views: 30476

Answers (2)

JC Sama
JC Sama

Reputation: 2204

There is a file helper in codeIgniter called file_helper.php in system/helpers that will help you do that :

$this->load->helper('file');
$data = 'My Text here';

if ( !write_file('./path/to/file.txt', $data)){
     echo 'Unable to write the file';
}

Full documentation about file_helper is here.

Upvotes: 5

Joerg
Joerg

Reputation: 3101

From the documentation:

$this->load->helper('file');

$data = 'Some file data';
    if ( ! write_file('./path/to/file.php', $data))
    {
            echo 'Unable to write the file';
    }
    else
    {
            echo 'File written!';
    }

Upvotes: 10

Related Questions