From the course: Learning the Standard PHP Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Exporting data to a download file with SplTempFileObject - PHP Tutorial
From the course: Learning the Standard PHP Library
Exporting data to a download file with SplTempFileObject
- The SplTempFile object class creates a temporary file that you can write to and read. What's interesting about this class is that the temporary file is stored in memory. If it exceeds the allocated amount, the file is automatically moved to the systems temp directory and then deleted when the script comes to an end. One application where this could be useful, is for creating a download file. I've opened tempfile.php which you can find in the chapter two folder of the exercise files. At the top of the page is a multidimensional array of exchange rates. Then lower down the page, those exchange rates are displayed in a table. Of course, this sort of information would normally come from a database but I'm using an array to keep the example simple. Then at the bottom of the page, is a form with a submit button. We're going to use this to allow the user to download the exchange rates as a CSV file and we'll use the SplTempFile object class to create the file. The name of the submit button…
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
-
-
-
-
Inspecting single directories with DirectoryIterator6m 52s
-
(Locked)
Inspecting single directories with FilesystemIterator5m 59s
-
(Locked)
Inspecting directories recursively with RecursiveDirectoryIterator6m 58s
-
(Locked)
Getting information about files with SplFileInfo5m 34s
-
(Locked)
Working on text files with SplFileObject8m
-
(Locked)
Using SplFileObject to convert a CSV to an array4m 25s
-
(Locked)
Exporting data to a download file with SplTempFileObject5m 24s
-
-
-
-
-
-
-