I've made an uploader for my site and now I got a problem. first take a look at this code
and now tell me where is the wrong with this code?
it gives me an error. that is
please give me a solution. where is the problem?
PHP Code:
<?
if(!$_POST['action'])
{
echo "<div class='line'>Select Image To Upload as Profile Pic</div>";
print "<form action=\"?alt=3\" method=\"post\" enctype=\"multipart/form-data\">";
print "<input class='inputAll' type='file' name='photo'>";
print "<input type=\"hidden\" name=\"action\" value=\"upload\">";
print "<input class='button' type=\"submit\" value=\"Upload\"></form>";
}
else
{
$photoname = $_FILES['photo']['name'];
$phototmpname = $_FILES['photo']['tmp_name'];
#$photo_size = getimagesize($phototmpname);
list($width,$height) = getimagesize($phototmpname);
$phototype = $_FILES['photo']['type'];
$photosize = $_FILES['photo']['size'];
$extens = file_extension($photoname);
echo $phototmpname."|".$photoname."|".$phototype."|".$extens."|".$width."|".$height;
$photo_rename = "$r.$extens";
if(!is_uploaded_file($phototmpname))
{
$error.="An Error Occured During Upload this Picture.<br/>";
}
if($phototype != image_type_to_mime_type(IMAGETYPE_GIF) && $phototype != image_type_to_mime_type(IMAGETYPE_PNG) && $phototype != image_type_to_mime_type(IMAGETYPE_JPEG))
{
$error.="Supported formats: GIF, JPEG and PNG.<br/>";
}
if(empty($error))
{
if($phototype=='image/jpeg')
{
$im=ImageCreateFromJPEG($phototmpname);
$tsrcs="./users/$nick/$photo_rename";
$n_width=130;
$n_height=150;
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
imageJPEG($newimage,$tsrcs,150);
}
elseif($phototype=='image/gif')
{
$im=imagecreatefromgif($phototmpname);
$tsrcs="./users/$nick/$photo_rename";
$n_width=130;
$n_height=150;
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
imagegif($newimage,$tsrcs,150);
}
elseif($phototype=='image/png')
{
$im=imagecreatefrompng($phototmpname);
$tsrcs="./users/$nick/$photo_rename";
$n_width=130;
$n_height=150;
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
$tmpPng =imagePNG($newimage,$tsrcs,100);
}
else
{
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
$tsrcs="./users/$nick/$photo_rename";
$n_width=130;
$n_height=150;
imagestring($im, 1, 5, 5, 'Error loading ' . $phototmpname, $tc);
$img = LoadPNG('bogus.image');
imagepng($img);
}
imagedestroy($im);
#--------------
$dbpx = protect($photo_rename);
$q = @mysql_query("update `users` set picture='$dbpx' where username='$nick';");
if($q)
{
$_SESSION['success'] = "Successfully Uploaded.";
$_SESSION['pic'] = "$dbpx";
header('Location: profile.php?nocache='.$r.'');
}
}
else
{
echo "<div class='error'>Error Found</div>";
echo $error;
echo "<div class='box'><a class='normal' href='?alt=3'>Back</a>";
echo "</div>";
}
}
?>
it gives me an error. that is
HTML Code:
Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /home/chatabox/public_html/files/upload.tpl on line 15
Comment