Here is a custom function I made that will delete all files in a folder older than N time.

Time here can be minutes, seconds or hours by using the strtotime() function. So for example, if you want to delete old files less than 4 hours, you can call strtotime(‘-4 hours’).

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.

Related Posts Plugin for WordPress, Blogger...