delete cache on webhosting

Cheatr01
Member | 3
+
0
-

Hi guys,

i have a problem with delete cache my Nette app on my hosting. In have this action in one of my presenter:

`

public function actionDeltemp(): void {
		FileSystem::delete(__DIR__ . '..\\..\\..\\temp\\cache\\');
		die();
	}

On localhost works fine but on hosting don`t work.

Thanks for your help…

nightfish
Member | 472
+
+1
-

Inspect error_log on your server to find any useful detail. And if that does not help you solve the problem, share them here.

EDIT: but there is a good chance the server runs on Linux, so you should prefer platform-agnostic directory separator:

FileSystem::delete(__DIR__ . \DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'temp'.\DIRECTORY_SEPARATOR.'cache'.\DIRECTORY_SEPARATOR);

or maybe a more _compact_ approach:

FileSystem::delete(\implode(\DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..', 'temp', 'cache', '']))

Last edited by nightfish (2019-02-03 20:53)

Pavel Kravčík
Member | 1182
+
0
-

@nightfish: And you can save three chars by using join() instead of implode.

Cheatr01
Member | 3
+
0
-

Thanks for replies guys, but still not works.

I looked on rights for temp dir (again) and are 777. Must be in Linux-Windows diferencies, but I don`t know where.

Milo
Nette Core | 1283
+
+1
-

@Cheatr01 Are you sure about the path? Looks like missing first back slash after __DIR__. Btw, not sure about backslash as a dir separator on Linux. Use /, works on Windows too.

Cheatr01
Member | 3
+
0
-

Work it!

Thx @Milo ! Answer was simple, like ussually. :-D