Post by musicweb » Mon Aug 31, 2015 8:18 am

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
}

Newbie

Posts

Joined
Mon Aug 17, 2015 7:23 pm

Post by dolrichfortich » Mon Aug 31, 2015 12:53 pm

change the code from
filesInDir($tdir.'/'.$file);

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

Opencart Options Pro, Reward Points For Review, DISQUS Comment Form,
Dolrich Fortich - Freelance web developer

Image


User avatar
New member

Posts

Joined
Thu Aug 05, 2010 8:09 pm
Location - Philippines

Post by musicweb » Mon Aug 31, 2015 7:43 pm

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.

Newbie

Posts

Joined
Mon Aug 17, 2015 7:23 pm

Post by dolrichfortich » Mon Aug 31, 2015 8:45 pm

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
}

Opencart Options Pro, Reward Points For Review, DISQUS Comment Form,
Dolrich Fortich - Freelance web developer

Image


User avatar
New member

Posts

Joined
Thu Aug 05, 2010 8:09 pm
Location - Philippines

Post by musicweb » Mon Aug 31, 2015 9:52 pm

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.

Newbie

Posts

Joined
Mon Aug 17, 2015 7:23 pm

Post by rph » Tue Sep 01, 2015 7:29 am

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().

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska
Who is online

Users browsing this forum: No registered users and 16 guests