Page 1 of 1

Call to undefined function

Posted: Mon Aug 31, 2015 8:18 am
by musicweb
Anyone know why I would be getting an error in the code?
The error says 'Call to undefined function filesInDir()'

Code: Select all

class ModelCatalogDownload extends Model {
function filesInDir()
{
$tdir = "/home/bruce/public_html/cat/system/download";
       $added = 0;
       $dirs = scandir($tdir);
        foreach($dirs as $file)
        {
                if (($file == '.')||($file == '..'))
                {
                }
                elseif (is_dir($tdir.'/'.$file))
                {
		filesInDir($tdir.'/'.$file);
                }
                else
                { 
do something here
}

Re: Call to undefined function

Posted: Mon Aug 31, 2015 12:53 pm
by dolrichfortich
change the code from
filesInDir($tdir.'/'.$file);

to this one
$this->filesInDir($tdir.'/'.$file);

Re: Call to undefined function

Posted: Mon Aug 31, 2015 7:43 pm
by musicweb
Tried that, but I get an error saying the connection was reset, and this is in my logs:
child pid 10510 exit signal Segmentation fault (11), possible coredump in /etc/apache2
If I run the script as a separate script outside of opencart, it works fine.

Re: Call to undefined function

Posted: Mon Aug 31, 2015 8:45 pm
by dolrichfortich
Try something like this. The previous one looks only at the at the assigned folder variable making it loop infinitely.

Code: Select all

class ModelCatalogDownload extends Model {
function filesInDir($tdir = "/home/bruce/public_html/cat/system/download")
{

       $added = 0;
       $dirs = scandir($tdir);
        foreach($dirs as $file)
        {
                if (($file == '.')||($file == '..'))
                {
                }
                elseif (is_dir($tdir.'/'.$file))
                {
                   $sub_dirs = $this->filesInDir($tdir.'/'.$file);
                }
                else
                {
do something here
}

Re: Call to undefined function

Posted: Mon Aug 31, 2015 9:52 pm
by musicweb
Kinda figured it was looping.
Your code works fine now, except that I need the subfolder in the output also.
Right now I get just the filenames.

Example:

2u543/2u543_goodlife_radio.mp3.
a1577/a1577_c'est_pas_ma_faute.mp3.

Re: Call to undefined function

Posted: Tue Sep 01, 2015 7:29 am
by rph
musicweb wrote:Anyone know why I would be getting an error in the code?
The error says 'Call to undefined function filesInDir()
That's a method, not a function. You can call it within the class with $this->filesInDir() or outside the class (after loading the model) with $this->model_catalog_download->filesInDir().