Skip to content
WJunction - Webmaster Forum

[php] list_files() function

Status
Not open for further replies.
i'm noob and sorry if this is a noob question. i wanna recode this so they'll only result one link and the latest one.

can't any hero wanna help me bout this? i'll very appreciate and sorry for my english. this code from leechviet.

PHP:
    function datecmp($a, $b)
    {
        return ($a[1] < $b[1]) ? 1 : 0;
    }
    function list_files()
    {
        $files = array();
        foreach ($this->jobs as $job)
        {
            if ($job['owner']!=$this->owner && !$this->bypass)
            {
                continue;
            }
            $files[] = array($job['hash'], $job['mtime'], $job['filename'], $job['msize'], $job['speed']/1024, empty($job['size']) ? 'N/A' : sprintf('%.1f%%', $job['msize']/$job['size']*100), $job['size'], $job['type']);
        }
        usort($files, array($this, 'datecmp')); //sorting the newest to oldest links
        $scheme = "<center><b><a href='?d=%s'>%s</a></b></center>";
                $this->CheckMBIP();
        $data = "";
                $data .= "<center><b>Your downloads: </b></center>";            
        foreach ($files as $file)
        {
            if ($file[7] == 'remote')
            {
                $data .= sprintf($scheme, $file[0], $file[2]);
            }
        }
        $data .= "";
        echo $data;
    }
 

2 comments

PHP:
function datecmp($a, $b)
    {
        return ($a[1] < $b[1]) ? 1 : 0;
    }
    function list_files()
    {
        $files = array();
        foreach ($this->jobs as $job)
        {
            if ($job['owner']!=$this->owner && !$this->bypass)
            {
                continue;
            }
            $files[] = array($job['hash'], $job['mtime'], $job['filename'], $job['msize'], $job['speed']/1024, empty($job['size']) ? 'N/A' : sprintf('%.1f%%', $job['msize']/$job['size']*100), $job['size'], $job['type']);
        }
        usort($files, array($this, 'datecmp')); //sorting the newest to oldest links
        $scheme = "<center><b><a href='?d=%s'>%s</a></b></center>";
                $this->CheckMBIP();
        $data = "";
                $data .= "<center><b>Your downloads: </b></center>";            
        $count = count($files);
        $count--;
        
        foreach ($files[$count] as $file)
        {
            if ($file[7] == 'remote')
            {
                $data .= sprintf($scheme, $file[0], $file[2]);
            }
        }
        $data .= "";
        echo $data;
    }
 
@nuclea
that didnt work either but thanks for your reply. really appreaciate that. somehow i've got it work. using current() function.

PHP:
    function datecmp($a, $b)
    {
        return ($a[1] < $b[1]) ? 1 : 0;
    }
    function list_files()
    {
        $files = array();
        foreach ($this->jobs as $job)
        {
            if ($job['owner']!=$this->owner && !$this->bypass)
            {
                continue;
            }
            $files[] = array($job['hash'], $job['mtime'], $job['filename'], $job['msize'], $job['speed']/1024, empty($job['size']) ? 'N/A' : sprintf('%.1f%%', $job['msize']/$job['size']*100), $job['size'], $job['type']);
        }
        usort($files, array($this, 'datecmp')); //sorting the newest to oldest links
        $scheme = "<center><b><a href='?d=%s'>%s</a></b></center>";
                $this->CheckMBIP();
        $data = "";
                $data .= "<center><b>Your downloads: </b></center>";            
        $files=array(current($files)); //return current value
        foreach ($files as $file)
        {
            if ($file[7] == 'remote')
            {
                $data .= sprintf($scheme, $file[0], $file[2]);
            }
        }
        $data .= "";
        echo $data;
    }
thanks again. solved.
 
Status
Not open for further replies.

About the author

N
Active Member · Joined
144
Messages
0
Reactions
16
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom