Trying to make a directory in a select list in an image upload form.

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]

<?php foreach ( $results['pages'] as $page ) { ?> <?php echo $page->pagename?> <?php } ?> [/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.

Actually it does make more sense to add it to the make page form and edit (option to delete page also folder) page form. Even if the directory stays empty. I do find more logic in that. I’ll attempt to go about it that way. I still need help in knowing how to implement the value of the select form. Meaning I need the value to be the final destination per image upload.

[php]
$folderoptionSelect = $page->pagename; // which would be the select form value
$filename = EXAMPLE_IMAGES_PATH . $folderoptionSelect . $_FILES[“file”][“name”];
[/php]

Something to this effect in the current setup. I’ll test a couple of different things out to see how to make it work. Any help is still and always will be appreciated.

As stated before I’m no longer attempting to make the directory through the upload form so I’m going to create a new thread to label the current issue in what I’m now attempting to do as to not cause confusion. The thread subject does not match what I want accomplished.

Sponsor our Newsletter | Privacy Policy | Terms of Service