From the course: PHP: Exporting Data to Files

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Saving the data to a local file

Saving the data to a local file - PHP Tutorial

From the course: PHP: Exporting Data to Files

Start my 1-month free trial

Saving the data to a local file

By default, the text in CSV classes, generate a download file. But, they also have the option to save a file to the web server's file system. The XML class, that we'll be working with later in this course. Also has this option. All three classes, implement this in exactly the same way. So, we'll look only at the text class. I've got to open cars_text.php from earlier in the chapter. The code on lines thirteen to fifteen, create a download file called cars_class.txt. And the options. The first one suppresses the car ID and transmission columns, and the second one sets the case of the labels, to uppercase. To save a file to the web server's file system, all you need to do is to set the local option to true. So let's just add another element to our options array. It's local, and we set the value to true. Instead of downloading cars_class.txt, this will save a copy of it, to the web server's file system. If the second argument to the constructor is just a file name, as it is here, the…

Contents