Welcome to PHP Smarty Q&A, where you can ask programmaing questions and receive answers from other members of the community for PHP, Smarty, MYSQL related. You can also share or save your scripts in this repository for future reference.

Smarty 3 $smarty->clear_compiled_tpl() Deletes all files including index.php

+1 vote
I am using Smarty 3. I have set $smarty->clear_compiled_tpl() to delete all template files from the temp directory.

Now, after setting this, it even deletes my index.php or index.html file. I do not want this to happen. As if some one accesses that directory without ndex.php or index.html file then they can see the list of files.

How can I set this smarty template that not to delete my ndex.php or index.html file?

Kindly help help help
asked Sep 13, 2015 in Smarty by Sanwer

1 Answer

0 votes
Best answer

I remembering doing this for one of my client. You need to edit smary sysplugin file.

Go here


Find the function

public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty)

Then find this line

if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {

And replace with this

if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false || $_file != "index.php") {

Hope it works for you. Let me know about it.

answered Sep 13, 2015 by robert (13,210 points)
Perfectly awesomely working as of now, thank you, thank you