EDITRESOLUTION NOTED IN CODEEDIT
Using this code it always dies at the copy part. Sometimes it creates the dir if it doesnt exsists like it is supposed to, sometimes it doesnt. Any help would be great.
<?
session_start();
require("config.php");
require("./lang/lang." . LANGUAGE_CODE . ".php");
require("functions.php");
include('dbinfo.inc.php');
include('css/popwin.css');
?> <head><title>.::Upload Image::.</title></head> <?
$username = $_SESSION['username@spechal.com'];
$gather = mysql_query("SELECT uid FROM calendar_users WHERE username='$username'") or die(mysql_error());
$getmore = mysql_fetch_assoc($gather);
$uid = $getmore['uid'];
$what = mysql_query("SELECT * FROM calendar_mssgs WHERE uid='$uid'") or die(mysql_error());
$howmany = mysql_num_rows($what);
if(!isset($_SESSION['username@spechal.com'])){
echo "Access Denied.";
}
if(isset($_POST['submit'])){
$title = $_POST['title'];
$dir = "/home/XXXXX/public_html/XXXXX/eventimages/".$title;
if (!file_exists($dir)){ mkdir($dir, 0777); } else { if(file_exists($dir) && is_dir($dir)){
$count = 0;
$handle=opendir($dir);
//resolution found here -- $file was being renamed and messed up
//so I changed $file to $check and everything is fine
while (($check = readdir($handle))!== false){ if ($check != "." && $check != "..") { $count++; }}}
$files = $count;
if($files >= 20) { echo "Maximum number of files per event has been reached."; } else {
$maxsize = 200000;
$file_size = $_FILES['file']['size'];
if($file_size >= $maxsize){ echo "File is too big. Your file size was $file_size Max size is $maxsize"; } else {
$file_name = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$ext = array('image/jpg', 'image/jpeg', 'image/gif', 'image/bmp', 'image/pjpeg');
if (!in_array($file_type, $ext)) {
echo "Error, not a valid file type<br>";
echo "You tried to upload $file_type";
exit;
} else {
if(copy($file, "$dir/$file_name")) { echo "File was successfully uploaded.<br>"; } else { echo "There was an error uploading your image.<br> Your image type was $file_type and size was $file_size <br>Name was $file_name your path was <br>$dir/$file_name<br><br>"; }
}}}}
echo "<font face='Tahoma' size='2'>";
echo "Images must be in .jpg, .jpeg, .gif or .bmp format and less than 200KB!</font><br>";
echo "<form action='$PHP_SELF' method='POST' enctype='multipart/form-data'>";
echo "<table><tr><td><font face='Tahoma' size='2'>Image to upload:</font></td><td><input type='file' name='file'></td></tr>";
echo "<tr><td><font face='Tahoma' size='2'>For event:</font></td><td><select name='where'>";
for($i=0; $i<$howmany; $i++){
$did = mysql_fetch_assoc($what);
$title = $did['title'];
echo "<option>$title</option>";
}
echo "</select></td></tr><tr><td><input type='submit' name='submit' value='Submit'></td></tr></table>";
} else {
echo "<font face='Tahoma' size='2'>Images must be in .jpg, .jpeg, .gif or .bmp format and less than 200KB!</font><br>";
echo "<form action='$PHP_SELF' method='POST' enctype='multipart/form-data'>";
echo "<table><tr><td><font face='Tahoma' size='2'>Image to upload:</font></td></tr><tr><td><input type='file' name='file'></td></tr>";
echo "<tr><td><font face='Tahoma' size='2'>For event:</font></td></tr><tr><td><select name='title'>";
for($i=0; $i<$howmany; $i++){
$did = mysql_fetch_assoc($what);
$title = $did['title'];
echo "<option>$title</option>";
}
echo "</select></td></tr><tr><td><input type='submit' name='submit' value='Submit'></td></tr></table>";
}
?>