note 59370 added to features.file-upload
| From: | daniel dot redinger at gmail dot com | Date: | Mon, 05 Dec 2005 02:42:28 +0000 |
| Subject: | note 59370 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99567@lists.php.net to get a copy of this message | ||
For some reason, I have not been able to create a working avatar system. It keeps on showing me this
error:
Notice: Undefined index: userfile in /var/www/shadowforum/{PAGE_NAME_HERE}.php on line 140
Invalid file type.
This is my code:
<?php
$maxwidthAva = "50"; // Max width allowed for avatars
$maxheightAva = "50"; // Max height allowed for avatars
if (isset($_POST['uploadit']))
{
$filetypeAva = $_FILES['userfile']['type'];
$filetypexAva = substr($filetypeAva,0,5);
if ($filetypexAva == "image")
{
$newidAva = "images/avatars/";
$newidAva .= base64_encode($user);
$newidAva .= ".gif";
$mysock = GetImageSize($_FILES['userfile']['tmp_name']);
$imagewidth = $mysock[0];
$imageheight = $mysock[1];
if ($imagewidthAva <= $maxwidthAva && $imageheightAva <=
$maxheightAva)
{
if(!(copy($_FILES['userfile']['tmp_name'], $newidAva)))
{
die("Cannot upload files.");
}
echo "You have successfully created a new avatar.";
}
else
{
echo "The avatar you've selected is to big, please change
it.";
}
}
else
{
echo "Invalid file type.";
}
}
else
{
$filename = "images/avatars/".base64_encode($user).".gif";
echo "<center>";
if (file_exists($filename))
{
echo "<img src=\"".$filename."\"
border=\"0\"><br>";
}
else
{
echo "[No Avatar]<br>";
}
?>
</center>
<form action="<?=$_SERVER['REQUEST_URI'] ?>"
method="post" enctype="multipart/form-data">
Select An Image: <input type="file" name="userfile"
size="18">
<br>
<input type="submit" value="Upload Avatar" name="uploadit"
size="18">
</form>
<br><br>
<i>Note: All uploaded files will be converted to .gif format.</i>
<?php
}
?>
Line 140: $filetypeAva = $_FILES['userfile']['type'];
If anyone could help me figure this problem out, I would be tremendously greatful!
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59370
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59370&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59370&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59370&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59370&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59370&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59370&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59370&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59370&report=yes
Search -- http://master.php.net/manage/user-notes.php