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/");
?>`

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.");  
    }   
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.