Page 1 of 1

[SOLVED] need some PHP help

Posted: Mon Jul 26, 2010 11:03 pm
by newagekat
Hi:

I'm using v1.8 of cmsms.  I've added a jquery slideshow that uses PHP to dynamically grab the images from a given folder.  Unfortunately, it also grabs the thumbnail that cmsms generates. 

I’m using this code to render images in a given folder for a dynamic slideshow.  However, it is including the thumbnails.

The solution I’ve been given is to change the if command:

Code: Select all

$directory = 'uploads/images/slideshow/' . $row['imageName']; 
try {    
    // Styling for images
    echo "<div id=\"myslides\">";
    foreach ( new DirectoryIterator("" . $directory) as $item ) {            
      if ($item->isFile()) {
            $path = "/newsite/" . $directory . "/" . $item;
            echo "<img src=\"" . $path . "\" />";
        }    
    }
    echo "</div>";
}

catch(Exception $e) {
    echo '<div style=\"line-height: 186px; text-align: center;\">No images found for this player.</div>';
}
To

Code: Select all

$directory = 'uploads/images/slideshow/' . $row['imageName']; 
try {    
    // Styling for images
    echo "<div id=\"myslides\">";
    foreach ( new DirectoryIterator("" . $directory) as $item ) {            
       if ($item->isFile() && !preg_match(‘/^thumb_/’, $item)) {
            $path = "/newsite/" . $directory . "/" . $item;
            echo "<img src=\"" . $path . "\" />";
        }    
    }
    echo "</div>";
}

catch(Exception $e) {
    echo '<div style=\"line-height: 186px; text-align: center;\">No images found for this player.</div>';
}
Unfortunately, cmsms spits out this error:
Invalid code entered.

Code: Select all

[color=red]Parse error:  syntax error, unexpected '^' in /home/keepsake/public_html/newsite/admin/edituserplugin.php(108) : eval()'d code on line 6[/color]
Any ideas how I can fix?

Re: need some PHP help

Posted: Tue Jul 27, 2010 1:06 am
by Nullig
I think the characters in red are incorrect:

    !preg_match(/^thumb_/,

It should be:

    !preg_match('/^thumb_/',

Nullig

Re: need some PHP help

Posted: Tue Jul 27, 2010 1:46 am
by newagekat
Nulig:

I'm not sure but both lines appear to be exactly the same.  What am I missing?

Re: need some PHP help

Posted: Tue Jul 27, 2010 2:04 am
by JeremyBASS
the first quote is a back tick.. ` not a signle quote ' the other is the same thing.. needs to be a signle quote.. hth cheers -Jeremy

Re: need some PHP help

Posted: Wed Jul 28, 2010 4:21 pm
by newagekat
Thank you for pointing that out.  I really did not notice.  Tried a few combination and finally got it working.  code s/b single quotes only

if ($item->isFile() && !preg_match('/^thumb_/', $item)) {