Alright, i'm having some problems with this code... the idea here is an edit profile type page were one can also upload an avatar for use in my forum. Now the problem: I got the upload and error checking code itself working, but when i embed it into my page among other php code it ceases to work. the error given regardless of of what is uploaded (and when nothing is selected) is : "wrong file type" which is part of my error checking code. upong removing that section of code, it gives me this error: getimagesize: Unable to open" for reading. this and some other testing leads me to beleive that somewhere along the line the $_FILES[] steam/array gets emptied/lost... purely because if you remove that code and put it in its own file it will run just fine.... with no getimagesize error..
This is driving me up the wall. below is the upload and error checking code embedded in the edit profile form.... any and all help is appreciated.
<?php
if( $_POST['change'] == "Change")
{
$link = mysql_connect("localhost", "emrys", "yeomen") or die("Could not connect to database");
mysql_select_db("ma", $link) or die("Could not select database");
$email=$_POST['email'];
$title=$_POST['title'];
$location=$_POST['location'];
$avatar=$_POST['avatar'];
$signature=nl2br($_POST['signature']);
/// error checking for avatar upload
$uploaddir = 'F:\phpdev\www\mypage\avatars\\';
$maxheight = '120';
$maxwidth = '120';
$maxfilesize = '23552';
if($_FILES['userfile']['size'] != '0')
{
if($_FILES['userfile']['type']=="image/jpeg" || $_FILES['userfile']['type']=="image/JPEG" ||
$_FILES['userfile']['type']=="image/jpg" || $_FILES['userfile']['type']=="image/JPG" ||
$_FILES['userfile']['type']=="image/gif" || $_FILES['userfile']['type']=="image/GIF" ||
$_FILES['userfile']['type']=="image/png" || $_FILES['userfile']['type']=="image/PNG" ||
$_FILES['userfile']['type']=="image/bmp" || $_FILES['userfile']['type']=="image/BMP")
{
$size = GetImageSize($_FILES['userfile']['tmp_name']);
list($foo,$width,$bar,$height) = explode("\"",$size[3]);
if(($width <= $maxwidth) && ($height <= $maxheight))
{
if($_FILES['userfile']['size'] <= $maxfilesize)
{
//$photopick=$_SESSION[username].".jpg";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name']))
{
print "file is valid, and was successfully uploaded.\n";
}
else
{
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
}
else
{
echo 'Image is too big, remember >=23KB';
}
}
else
{
print("Wrong dimensions: needs 120x120 pixels and yours is $height x $width");
}
}
else
{
echo "wrong file type";
}
}
else
{
echo "no file specified";
}
// ^error checking for avatar upload/
mysql_query("UPDATE members SET email = '$email', title = '$title', location = '$location', avatar = '$avatar', signature = '$signature' WHERE username='".$_SESSION['username']."'") or die (mysql_error());
mysql_free_result($result2);
mysql_close();
echo 'Details successfully changed';
}
else
{
?>
<br>
<form action="<?php $PHP_SELF ?>" method="post">
Username: <?php echo $username; ?> <br>
Joined: <?php echo $joined; ?> <br>
Posts: <?php echo $num_posts; ?> <br>
Bytes: not yet implimented <br>
Password:<input type="password" name="password" size="20"><br>
Password:<input type="password" name="password1" size="20"><br>
Email: <input type="text" name="email" value="<?php echo $email; ?>" size="20"><br>
Title: <input type="text" name="title" value="<?php echo $title; ?>" size="64"> This is a chance for you to be witty. (no more than 64 characters) <?php echo strlen($title); ?><br>
Location: <input type="text" name="location" value="<?php echo $location; ?>" size="64"> Another Chance to be witty. (no more than 128 characters)<br>
Avatar: <br><?php if($avatar !=NULL){?><img src="<?php echo $avatar; ?>" border="0" alt=""><?php } ?> <br>
<form enctype="multipart/form-data" action="<?php $PHP_SELF ?>" method="post" >
Upload avatar: <input type="file" name="userfile">
<?php echo "NOTE: Max dimensions are 120x120 and 23KB"; ?>
<br>
<br>
Signature: <br><textarea wrap="virtual" name="signature" rows="5" cols="50"><?php echo $signature; ?></textarea><br><br>
<input type="Submit" name="change" value="Change">
</form>
<?php
} //end else
Thanks alot
-emrys