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 - PHP Tutorial
From the course: PHP: Exporting Data to Files
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Outputting the database result to a text file6m 32s
-
(Locked)
Outputting the result as a CSV file6m 53s
-
(Locked)
Introducing the Base class for file downloads4m 37s
-
(Locked)
Using the Text class for greater control over output7m 20s
-
(Locked)
Controlling CSV options with the Csv class6m 49s
-
(Locked)
Saving the data to a local file6m 36s
-
(Locked)
-
-
-
-
-
-