Post by albertgracias » Thu Mar 31, 2022 6:54 pm

Hi
i was deleting the cache files accidently deleted wrong files, i did manage to locate and replace them, but the site and the admin panel is still showing error 500, on errror log page i see

[31-Mar-2022 19:23:17 Asia/Dili] PHP Parse error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /home/kunalshah4177/public_html/system/library/cache/file.php on line 4

this is my file.php page
-------------------------------------------------------------
<?php
namespace Opencart\System\Library\Cache;
class File {
private int $expire;

public function __construct(int $expire = 3600) {
$this->expire = $expire;

$files = glob(DIR_CACHE . 'cache.*');

if ($files) {
foreach ($files as $file) {
$filename = basename($file);

$time = substr(strrchr($file, '.'), 1);

if ($time < time()) {
$this->delete(substr($filename, 6, strrpos($filename, '.') - 6));
}
}
}
}

public function get(string $key): array|string|null {
$files = glob(DIR_CACHE . 'cache.' . basename($key) . '.*');

if ($files) {
$handle = fopen($files[0], 'r');

flock($handle, LOCK_SH);

$size = filesize($files[0]);

if ($size > 0) {
$data = fread($handle, $size);
} else {
$data = '';
}

flock($handle, LOCK_UN);

fclose($handle);

return json_decode($data, true);
}

return [];
}

public function set(string $key, array|string|null $value, int $expire = 0): void {
$this->delete($key);

if (!$expire) {
$expire = $this->expire;
}

$file = DIR_CACHE . 'cache.' . basename($key) . '.' . (time() + $expire);

$handle = fopen($file, 'w');

flock($handle, LOCK_EX);

fwrite($handle, json_encode($value));

fflush($handle);

flock($handle, LOCK_UN);

fclose($handle);
}

public function delete(string $key): void {
$files = glob(DIR_CACHE . 'cache.' . basename($key) . '.*');

if ($files) {
foreach ($files as $file) {
if (!@unlink($file)) {
clearstatcache(false, $file);
}
}
}
}
}

-----------------------------------------------------------------------------------------------------------------------


please help

Newbie

Posts

Joined
Sat Oct 11, 2014 7:59 pm

Post by halfhope » Thu Mar 31, 2022 7:14 pm

Hey!

It seems you downloaded the files from github.
  • Look at the opencart version in index.php
  • Download this version from the download page
  • Replace these files again.
When contacting the forum, indicate the version of the opencart. After the issue is resolved, add [SOLVED] to the beginning of the topic title.

My FREE extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by albertgracias » Mon Apr 04, 2022 4:48 pm

:)
halfhope wrote:
Thu Mar 31, 2022 7:14 pm
Hey!

It seems you downloaded the files from github.
  • Look at the opencart version in index.php
  • Download this version from the download page
  • Replace these files again.
When contacting the forum, indicate the version of the opencart. After the issue is resolved, add [SOLVED] to the beginning of the topic title.

solved
thank you for your help,

Newbie

Posts

Joined
Sat Oct 11, 2014 7:59 pm

Post by straightlight » Mon Apr 04, 2022 9:30 pm

albertgracias wrote:
Mon Apr 04, 2022 4:48 pm
:)
halfhope wrote:
Thu Mar 31, 2022 7:14 pm
Hey!

It seems you downloaded the files from github.
  • Look at the opencart version in index.php
  • Download this version from the download page
  • Replace these files again.
When contacting the forum, indicate the version of the opencart. After the issue is resolved, add [SOLVED] to the beginning of the topic title.

solved
thank you for your help,
Now that the issue has been solved, please add: [SOLVED] at the beginning of the subject line on your first post.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 0 guests