The idea here is to have the image being uploaded and resized to the directory of choice within the select list. The select list displays the names of pages. Pages from the database.
[php]$pages as $page[/php]
The directories won’t exist through the edit or add pages form because adding images to the page will be optional so it has to or should only be created when uploading images for the page. I do plan on creating a way to delete it through the edit form though. The script I’m using to upload and resize image (thanks to the help of Senior Member richei) is as follows:
[php]
if (isset($_POST[‘submit’])) {
$image = $_FILES[“file”][“name”];
$uploadedfile = $_FILES[‘file’][‘tmp_name’];
if ($image){
$filename = stripslashes($_FILES[‘file’][‘name’]);
$allowedExts = array(“image/jpeg”,“image/pjpeg”);
foreach ($allowedExts as $img_type) {
if ($img_type == $_FILES[“file”][“type”]) {
$typeOK = true;
if (file_exists(EXAMPLE_IMAGES_PATH . $_FILES[“file”][“name”])) {
// Do something
}
else {
$image = $_FILES[“file”][“name”];
$uploadedfile = $_FILES[‘file’][‘tmp_name’];
$filename = stripslashes($_FILES[‘file’][‘name’]);
$extension = getExtension($filename);
$extension = strtolower($extension);
$uploadedfile = $_FILES[‘file’][‘tmp_name’];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
$newwidth = 290;
$newheight = 190;
$tmp = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = EXAMPLE_IMAGES_PATH . $_FILES[“file”][“name”];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
// Do some more stuff
}
break;
}
else { $typeOK = false;
// Do something
}
}
}
else {
// Do something else
}
}
[/php]
I’m not sure where or how to implement the make directory function with this form. Here’s how I have the select list being displayed :
[php]
This of course list all the page names of pages. I need something of the following to work :
[php]
$PAGEimgsfolder = $page->pagename // which would be the select form value
mkdir(EXAMPLE_IMAGES_PATH . $PAGEimgsfolder, 0700);
[/php]
Thanks to all in advance for any suggestions on how to accomplish this would be love beyond measure.