Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Building a gallery.

Name: Anonymous 2009-10-05 19:31

Is this the where I can cry about how terrible I am at PHP? :O

I am trying to make a gallery, and I would like the array to sort by the latest pictures added to be first on the list.

What I currently have working is:
if ($dirHandle = opendir($galleryDir)) {
    while (($file = readdir($dirHandle)) !== false) {
        if (isImage("$galleryDir/$file")) {
            $images[] = $file;
        }
    }
    closedir($dirHandle);
}
I figured readdir would let me make it so when I told the directory to sort by date, the gallery page would, such is not the case, it seems eternally alphabetical.

I was tinkering with:
function LoadFiles($dir)
{
 $Files = array();
 $dir          = "porn/images";
 $It =  opendir($dir);
 if (! $It)
  die('Cannot list files for ' . $dir);
 while ($Filename = readdir($It))
 {
  if ($Filename == '.' || $Filename == '..')
   continue;
  $LastModified = filemtime($dir . $Filename);
    $Files[] = array($dir .$Filename, $LastModified);
 }

  return $Files;
}
function DateCmp($a, $b)
{
  return ($a[1] < $b[1]) ? -1 : 0;
}

function SortByDate(&$Files)
{
  usort($Files, 'DateCmp');
}

$Files = LoadFiles('data/');
SortByDate($Files);

But I get Warning: filemtime() [function.filemtime]: stat failed for  file

Can anyone help me, perchance?  I am no good at computers, how did this cat get here? =(^.^)=

Thanks in advance~

Name: Anonymous 2009-10-05 19:35

Some people, when confronted with a problem, think
“I know, I'll use PHP.”   Now they have two problems.

Haskell is the right tool for this job.

Name: Anonymous 2009-10-05 19:58

>>2
You must be this Haskell I keep hearing so much about.

Name: Anonymous 2009-10-05 22:20

CL macros php is retarded.

Name: Anonymous 2009-10-05 23:58

lrn2codetags

Name: Anonymous 2009-10-06 0:05

filemtime($dir . '/' . $Filename);

Name: Anonymous 2009-10-06 0:09

>function LoadFiles($dir)
>{
$dir          = "porn/images";

WHY


function LoadFiles($dir = 'porn/images')
{
    //hurf
}

Name: sage 2009-10-06 0:19

I see your problem. You are writing your PHP like a fag. Do it this way:

class Main {
    public
        $file,
        $dirhandle,
        $gallerydir,
       
    public function Main() {
        if ($dirhandle = opendir($gallerydir)):
            while ($file = readdir($dirhandle)) != false):
                if (isImage("$gallerydir/$file")):
                    $images[] = $file;
                endif;
            endwhile;
            closedir($dirhandle);
        endif;
    }

Name: Anonymous 2009-10-06 0:41

>>6
I appreciate your assistance.  That leaves me in the same boat, stat failed.

Name: Anonymous 2009-10-06 0:49

>>8
Is that some PyHP++?

Name: Anonymous 2009-10-06 3:55

>>8


images = Dir['gallery/**/*.jpg'].sort_by {|x| test(?M, x)}.reverse
images.each {|image| puts image}


Fucking hell is PHP ugly.

Name: Anonymous 2009-10-06 7:02

>>11
that's ruby, not PHP.

Name: Anonymous 2009-10-06 7:35

>>12

IHBT

Name: Anonymous 2010-12-06 9:03

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2010-12-20 20:20

Name: Anonymous 2011-02-03 6:34

Don't change these.
Name: Email:
Entire Thread Thread List