The form I’m creating allows the admin to upload images to a directory. The form works as expected but now I’m trying to have the directory be different according to the option selected. The html output is as follows :
[php]
<?php foreach ( $results['pages'] as $page ) { ?> <?php echo $page->pagename?> <?php } ?>Submit
<?php if ( isset( $results['status'] ) ) { ?> <p><?php echo $results['status'] ?></p>
<?php } ?>
[/php]
The php script for the form is as follows :
[php]
$results = array();
$data = Page::getList();
$results[‘pages’] = $data[‘results’];
$results[‘totalRows’] = $data[‘totalRows’];
function getExtension($str) {
$tmp = explode(’.’, $str);
return $tmp[1];}
if (isset($_POST[‘submit’])) {
$pageImgFolder = $page->pagename;
$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(The_IMAGES_PATH . “/” . $pageImgFolder . $_FILES[“file”][“name”])) {
$results[‘status’] = "Text to display ";
}
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 = The_IMAGES_PATH . “/” . $pageImgFolder . $_FILES[“file”][“name”];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
$results[‘imgLoaded’] = $_FILES[“file”][“name”];
$results[‘status’] = "Text to display ";}break;}
else { $typeOK = false;
$results[‘status’] = "Text to display ";
}
}
}
else {
$results[‘status’] = "Text to display ";
}
}
[/php]
The script works as is but will not upload to the directory of choice using the select option. The error that I’m receiving is - Undefined variable: page on the line below:
[php]
$pageImgFolder = $page->pagename;
[/php]
The select box list the names so that part works. My question is how to define the variable and once it is defined will the value be excepted as far as saving it to the directory of choice? Help on this would be awesome in my learning experience and so much appreciated.