0

I want to make it create the upload folder by itself.right now it creates the thumbs and so

but I want the script to create the folder automatically

<?php
function createThumbs($pathToImages, $pathToThumbs, $thumbWidth) {
$dir = opendir($pathToImages);
while(false !== ($fname = readdir($dir))) {
$info = pathinfo($pathToImages . $fname);
if( strtolower($info['extension']) == 'jpg' ) {
echo "Creating thumbnail for {$fname} <br />";

$img = imagecreatefromjpeg( "{$pathToImages}{$fname}");
$width = imagesx ($img);
$height = imagesy ($img);

$new_width = $thumbWidth;
$new_height = floor ($height * ( $thumbWidth / $width));

$tmp_img = imagecreatetruecolor($new_width, $new_height);

imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

imagejpeg($tmp_img, "{$pathToThumbs}{$fname}" );
}
}
closedir($dir);
}
createThumbs("upload/", "upload/thumbs/", 200);
?>

<?php
function createGallery($pathToImages, $pathToThumbs) {
echo "Creating gallery.html <br />";

$output = "<html>";
$output = "<head><title>Thumbnails</title></head>";
$output = "<body>";
$output = "<table cellspacing=\"0\" cellpadding=\2\" width=\"500\">";
$output = "<tr>";

$dir = opendir($pathToThumbs);

$counter = 0;

while(false !== ($fname = readdir($dir))) {
if($fname != '.' && $fname != '..') {
$output .= "<td valign=\"middle\" align=\"center\"><a href=\" {$pathToImages}{$fname}\">";
$output .= "<img src=\"{$pathToThumbs}{$fname}\" border=\"0\" />";
$output .= "</a></td>";

$counter += 1;
if($counter % 4 == 0) {
$output .= "</tr><tr>";
}
}
}
closedir($dir);
$output .= "</tr>";
$output .= "</table>";
$output .= "</body>";
$output .= "</html>";

$fhandle = fopen("gallery.html", "w");
fwrite($fhandle, $output);
fclose($fhandle);

}
createGallery("upload/", "upload/thumbs/");
?>`
2
Contributors
1
Reply
10
Views
4 Years
Discussion Span
Last Post by pixelsoul
0

you could always do something like

mkdir($pathToImages);

In your code somewhere after checking if the directory exists.

Something like

if(!file_exists($pathToImages)) {  
    if(!mkdir($pathToImages)) {  
        die("There was a problem generating a thumbnail.");  
    }   
}

Edited by pixelsoul

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.