You only need 3 headers to make this work and 1 or 2 more lines after that. That is all you need to add in order to have any binary file to force download itself whenever the PHP file is called.

The path to file variable is the absolute path of the file that you wish to have the user force download it.

The 3 headers are important, otherwise they won’t work. The basename function is also important in case you might pass a variable that contains the absolute path of the filename and we do not want other users to see the file structure of your server.

The basename function removes all directory paths and returns the name of the file itself.

That’s it! Easy, right?

By default, Recess PHPs’s JsonView class responds with the properties of your controller. So even if you create a custom route that outputs only an array, a default row of the controller’s model will also be included with null values.

You can override this using the OKResponse class. You can do it like this.

While this is not really an error, extra data that is not used should not be included in any output as it will only add to the extra bytes.

When you look at your JSON output, you realized the column names and values also have extra index column numbers and the associated values included.

To remove this, simply add an option in the PDO when you instantiate a database connection in PHP like this:

That should fix the problem. When you use json_encode(), there will be no more duplicate values with the corresponding column index number as key.

Related Posts Plugin for WordPress, Blogger...