note 50507 added to features.file-upload
| From: | ansarka at rediffmail dot com | Date: | Wed, 02 Mar 2005 08:50:28 +0000 |
| Subject: | note 50507 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85769@lists.php.net to get a copy of this message | ||
Hello sir's
I have written a code to upload gif and jpeg files but files after uploading the photo is not
clear also the image size is also increasing . Any one please help me
My code is given below
---------------------------------------
<form name="frmreg" method="POST" onSubmit="return validate()"
action="myupload.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" >
<input type="file" name="up_file" size="43"
class="input">
-------------------------------
myupload.php
<?
if(!empty($_FILES["up_file"]))
{
$uploaddir = "../images/photos";// set this to wherever
// echo $uploaddir.$HTTP_POST_FILES["up_file"]["name"];
//echo $HTTP_POST_FILES["up_file"]["tmp_name"];
if ($_FILES["up_file"]["type"]=="image/pjpeg")
{
$a=$_FILES["up_file"]["name"];
$b=$user_id;
$fn1="$uploaddir/net_er".$b.".jpg";
$fn="$uploaddir/net_er".$b.".gif";
if(file_exists($fn))
{
unlink($fn);
}
if(file_exists($fn1))
{
unlink($fn1);
}
if ($_FILES["up_file"]["size"]>1024*60)
{
redirectto("uploadphoto_size_error.php");
}
else if (move_uploaded_file($_FILES["up_file"]["tmp_name"],
$uploaddir."/" . $_FILES["up_file"]["name"]))
{
rename("$uploaddir/".$a, "$uploaddir/net_er".$b.".jpg");
redirectto("member_home.php");
}
else
{
redirectto("upload_error.php");
}
}
else if($_FILES["up_file"]["type"]=="image/gif")
{
$a=$_FILES["up_file"]["name"];
$b=$user_id;
$fn1="$uploaddir/net_er".$b.".jpg";
$fn="$uploaddir/net_er".$b.".gif";
if(file_exists($fn))
{
unlink($fn);
}
if(file_exists($fn1))
{
unlink($fn1);
}
if ($_FILES["up_file"]["size"]>1024*60)
{
redirectto("uploadphoto_size_error.php");
}
else if (move_uploaded_file($_FILES["up_file"]["tmp_name"], $uploaddir .
$_FILES["up_file"]["name"]))
{
rename("$uploaddir".$a, "$uploaddir".$b.".gif");
redirectto("member_home.php");
}
else
{
redirectto("upload_error.php");
}
}
else
{ redirectto("uploadphoto_type_error.php");
}
}
else
{
redirectto("upload_error.php");
}
?>
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50507
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50507&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50507&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50507&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50507&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50507&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50507&report=yes
Search -- http://master.php.net/manage/user-notes.php