PHP Coding Academy mini-book problems

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

PHP Coding Academy mini-book problems

Postby CaptainPasty » Sat Aug 28, 2010 10:41 am

Hi all,

I bought issue 135 of the magazine and (like many people by the sounds of it) found the PHP Coding Academy mini-book that came with it a great little time consumer,but...

By the time I'd gotten to Project 3, page 48 I found myself going around in circles. After saving the code and refreshing the page nothing happens (blank page). I've had a quick look in the "thumbnails" folder and it doesn't seem to be saving them.

Is there a miss-print in the book or (more likely) am I doing something really stupid? I've included my code below so if anyone can help I'd be really grateful:

<?php
$images=scandir("images");
$thumbnails=scandir("thumbnails");

$new_pics=array_diff($images,$thumbnails);

foreach($new_pics as $pic){
//load the original image
$image=imagecreatefromjpeg("images/$pic");

//and save it with %10 quality
imagejpeg($image,"thumbnails/$pic",10);
}

//now loop again, printing out images and links
foreach($images as $image){
//note that we have an <img> inside an <a>
echo"<a href=\"images/$image\"><img
src=\"thumbnails/$image\"/></a>";
}
?>
CaptainPasty
 
Posts: 5
Joined: Sat Aug 28, 2010 10:00 am
Location: Manchester

php project 3 blank page

Postby shanita » Sun Aug 29, 2010 5:04 pm

Hi CaptainPasty,

I checked your code (with copy and paste) and it is working perfectly well on my computer.
Maybe you forgot to install php5-gd. This package provides a module for handling graphics directly from php scripts. It supports the png, jpeg, xpm formats.

Good luck
User avatar
shanita
 
Posts: 9
Joined: Fri Aug 25, 2006 3:20 pm
Location: Belgium

Post subject: php project 3 blank page

Postby CaptainPasty » Mon Aug 30, 2010 9:27 am

It wouldn't surprise me at all if I've done that! Thanks for your help, Shanita. I'll give it a go...
CaptainPasty
 
Posts: 5
Joined: Sat Aug 28, 2010 10:00 am
Location: Manchester

Post subject: php project 3 blank page

Postby CaptainPasty » Mon Aug 30, 2010 9:39 am

Just wanted to say thanks. Pulled up Synaptic and php5-gd hadn't been installed. Installed, rebooted and now works fine.

Saved me a lot of headaches!
CaptainPasty
 
Posts: 5
Joined: Sat Aug 28, 2010 10:00 am
Location: Manchester


Return to Programming

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest