is there anything wrong with this uploader?

Started on the old forum in September 2011 · view the original in the archive · old links redirect here

7 replies · 624 views · started 15 years ago · 1 min read

4 participants
asifnayem Developer · 119 posts #1

I've made an uploader for my site and now I got a problem. first take a look at this 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>";
}
}

?>

and now tell me where is the wrong with this code?

it gives me an error. that is

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /home/chatabox/public_html/files/upload.tpl on line 15

please give me a solution. where is the problem?

khan Lead · 681 posts #2

the problem is

$phototmpname = $_FILES['photo']['tmp_name'];

is not responding i guess. and this kinds of uploader can consume high cpu uses.

asifnayem Developer · 119 posts #3

so what should i do to solve the problem bro? This code works fine on localhost. but online it gives me this error. and how to solve the high cpu uses?

subzero Super moderator Fellow · 3,954 posts #4

reg golbals need to be turn on

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

asifnayem Developer · 119 posts #5

if reg global is on, isnt there would be security problem?

subzero Super moderator Fellow · 3,954 posts #6

for uploaders there is bro

But if you wish to host a uploader that is better on cpu and safe to use

then i will build one and charge you $15 for it...

If no i can't help you.

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close