Hello, this is my first post I hope you guys can help me out here, basically whats going on is I declare a variable "$diree" then I insert it in a function but its not getting recognized, here is the code:
$institutea "some directory";
$dire = str_replace(" ","-",$institutea);
# SETTINGS
$max_width = 110;
$max_height = 130;
$per_page = 5;
$page = $_GET['page'];
$has_previous = false;
$has_next = false;
function getPictures() {
global $page, $per_page, $has_previous, $has_next;
if ( $handle = opendir($diree.'/') ) { // done changes here
$lightbox = rand();
?><table border="1"><tr><td>
<form action="pro.php" method="post">
<?php
echo "<ul id='pictures'>";
$count = 1;
$skip = $page * $per_page;
if ( $skip != 0 )
$has_previous = true;
while ( $count < $skip && ($file = readdir($handle)) !== false ) {
if ( !is_dir($file) && ($type = getPictureType($file)) != '' )
$count++;
}
$count = 1;
while ( $count < $per_page && ($file = readdir($handle)) !== false ) {
if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
if ( ! is_dir($dire .'/') ) { // done changes here
mkdir($dire .'/'); // done changes here
}
if ( ! file_exists($dire .'/'.$file) ) {
makeThumb( $file, $type );
}
echo '<li>';
echo '<img src="'.$dire .'/'.$file.'" alt="" / width="110" height="110"><br/><input type="checkbox" name="food[]" value='.$file.'>'; // done changes here
echo '</li>';
$count++;
}
}
echo '</ul>';
?>
</td></tr><tr><td><div align="center"><input type="submit" value="Add"></div></td></tr>
</tr></table></form>
<?php
while ( ($file = readdir($handle)) !== false ) {
if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
$has_next = true;
break;
}
}
}
}
function getPictureType($file) {
$split = explode($dire .'/', $file);
$ext = $split[count($split) - 1];
if ( preg_match('/jpg|jpeg/i', $ext) ) {
return 'jpg';
} else if ( preg_match('/png/i', $ext) ) {
return 'png';
} else if ( preg_match('/gif/i', $ext) ) {
return 'gif';
} else {
return '';
}
}
function makeThumb( $file, $type ) {
global $max_width, $max_height;
if ( $type == 'jpg' ) {
$src = imagecreatefromjpeg($file);
} else if ( $type == 'png' ) {
$src = imagecreatefrompng($file);
} else if ( $type == 'gif' ) {
$src = imagecreatefromgif($file);
}
if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {
$newW = $oldW * ($max_width / $oldH);
$newH = $max_height;
} else {
$newW = $max_width;
$newH = $oldH * ($max_height / $oldW);
}
$new = imagecreatetruecolor($newW, $newH);
imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
if ( $type == 'jpg' ) {
imagejpeg($new, $dire .'/'.$file);
} else if ( $type == 'png' ) {
imagepng($new, $dire .'/'.$file);
} else if ( $type == 'gif' ) {
imagegif($new, $dire .'/'.$file);
}
imagedestroy($new);
imagedestroy($src);
}
?>