Post by kuba1999 » Fri Mar 21, 2008 10:25 pm

I have got a problem. My web: http://rybarstvi-ustiky.cz/upload/

Admin
user: admin
pass: admin

Look:

Warning: Invalid argument supplied for foreach() in /mnt/data/accounts/k/kuba1999/data/www/upload/library/cache/cache.php on line 26

Warning: Invalid argument supplied for foreach() in /mnt/data/accounts/k/kuba1999/data/www/upload/library/cache/cache.php on line 37


Where is problem? (in cache.php)

My code cache.php

Code: Select all

<?php
class Cache { 
	var $expire = 3600;
	
  	function __construct() {
    	foreach (glob(DIR_CACHE . 'cache.*') as $file) {
      		$array = explode('.', end(explode('/', $file)));

      		if ($array[2] < time()) {
				unlink($file);
      		}
    	}
  	}
		
  	function set($key, $value) {
    	$this->delete($key);

    	$file = fopen(DIR_CACHE . 'cache.' . $key . '.' . (time() + $this->expire), 'a');

    	fwrite($file, serialize($value));
		
    	fclose($file);
  	}

  	function get($key) {
    	foreach (glob(DIR_CACHE . 'cache.' . $key . '.*') as $file) {
      		$handle = fopen($file, 'r');
      		$cache  = fread($handle, filesize($file));
	  
      		fclose($handle);

      		return unserialize($cache);
    	}
  	}
 
  	function delete($key) {
    	foreach (glob(DIR_CACHE . 'cache.' . $key . '.*') as $file) {
      		unlink($file);
    	}
  	}
}
?>
Thanks.  :)

Newbie

Posts

Joined
Fri Mar 21, 2008 10:19 pm

Post by bruce » Sun Mar 23, 2008 3:24 pm

Try this as a replacement for cache.php and let me know how you go. Please back up your original first.

Code: Select all

<?php
class Cache 
{ 
	var $expire = 3600;
	
  	function __construct() 
    {
    	$files = glob(DIR_CACHE . 'cache.*');
        if ($files)
        {
            foreach ($files as $file) 
            {
      		    $array = explode('.', end(explode('/', $file)));

      		    if ($array[2] < time()) 
                {
				    unlink($file);
      		    }
    	    }
        }
  	}
		
  	function set($key, $value) 
    {
    	$this->delete($key);

    	$file = fopen(DIR_CACHE . 'cache.' . $key . '.' . (time() + $this->expire), 'a');

    	fwrite($file, serialize($value));
		
    	fclose($file);
  	}

  	function get($key) 
    {
    	$files = glob(DIR_CACHE . 'cache.' . $key . '.*');
        if ($files)
        {
            foreach ($files as $file) 
            {
                $handle = fopen($file, 'r');
                $cache  = fread($handle, filesize($file));

                fclose($handle);

                return unserialize($cache);
            }
        }
  	}
 
  	function delete($key) 
    {
    	$files = glob(DIR_CACHE . 'cache.' . $key . '.*');
        if ($files)
        {
            foreach ( $files as $file) 
            {
      		    unlink($file);
    	    } 
        }
  	}
}
?>


Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by kuba1999 » Sun Mar 23, 2008 5:05 pm

BRUCE.... Very, very thanks..... E-shop haven´t got any problems.

Sorry my ENGLISH is horrible.... I am czech  :)
Last edited by kuba1999 on Sun Mar 23, 2008 9:11 pm, edited 1 time in total.

Newbie

Posts

Joined
Fri Mar 21, 2008 10:19 pm

Post by bruce » Sun Mar 23, 2008 7:46 pm

My pleasure. Don't apologise for your english, I can't speak czech at all.  :)

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by Daniel » Wed Mar 26, 2008 7:59 pm

I'll add thistothenext release.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by OrT » Mon May 05, 2008 3:56 pm

Helped me out, thanks very much!

OrT
Newbie

Posts

Joined
Sun Mar 02, 2008 10:21 pm

Post by pdbs » Thu May 08, 2008 2:58 am

THANK YOU    This was the fix for my issue. the current cart zip files needs this fix.  Please update the release with this change  May, 2008 download still has this issue.

New member

Posts

Joined
Thu May 08, 2008 2:56 am

Post by gibpat » Fri Jul 04, 2008 11:35 am

Cheers!
Fixed me aswell :D

-dave

New member

Posts

Joined
Fri Jun 06, 2008 9:09 am

Post by fido-x » Fri Jul 04, 2008 4:32 pm

Hey Bruce,

I don't mean to be rude or anything, but I think you made a mistake in your code. Where you've got -

Code: Select all

<?php
class Cache 
{ 
	var $expire = 3600;
	
  	function __construct() 
    {
    	$files = glob(DIR_CACHE . 'cache.*');
        if ($files)
        {
            foreach ($files as $file) 
            {
      		    $array = explode('.', end(explode('/', $file)));

      		    if ($array[2] < time()) 
                {
				    unlink($file);
      		    }
    	    }
        }
  	}
		
  	function set($key, $value)
The second closing brace before the "function set($key, $value) closes the Cache class, subsequently the functions "set, get and delete" are not even being read into the class.

Regards, Fido-X

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by fido-x » Fri Jul 04, 2008 5:41 pm

Hi Bruce,

Sorry about that, ignore that last post. Although it appears to have an extra closing brace, if I remove it, the whole site breaks. I was wrong.

Regards, Fido-X

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by bruce » Fri Jul 04, 2008 8:47 pm

aaah, it is all in the testing  :D

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by ankur » Sun Jul 13, 2008 7:21 pm

Hi Bruce,
This code working with Firefox and with IE but with Opera I can't open my Shop. Do you know, what is the problem?

Regards

Newbie

Posts

Joined
Sun Apr 27, 2008 6:54 pm

Post by bruce » Sun Jul 13, 2008 9:01 pm

Posting the url of your shop would help a little.

However, the code referred to in this thread is server side and the choice of browser does not affect its function. It is likely you have some other problem, most likely related to a template or css modification.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm
Who is online

Users browsing this forum: No registered users and 11 guests