I have this code and I need to make this work:
if ($handle = opendir("images/")) { $i=0;
while (false !== ($file = readdir($handle))){
if ($file != "." && $file != ".." && $file != "Recursive Dir_Renfiles_dirname-filename.php") {
$filename[$i]=$file;
$i++;
}}}
//print_r($filename);
foreach($filename as $filename){
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_p, null, 100);
}
I there a way to make this work? Or is there another way to do this?
If you want multiple images on one page, you should use this PHP file to produce one image, and then use the PHP file as the source in an HTML image tag, like this:
NOTE:
When getting the filename via
$_GET, it would be a good idea to watch out for unexpected characters, especially slashes. Someone could call the URL like this:picture.php?filename=../badImage.jpg, which may display a file in a different folder than you want them to have access to. So perhaps do something like$_GET["filename"] = stripslashes($_GET["filename"]);or something.