Multiuser Profile Photo Upload

Hi there,

I am currently doing a website that will enable multiuser to have their accessing account. When come to the profile photo upload part, I have problem.

This is the code I have now:

HTML form:
HTML Code:

<form name="addPict" action="Photo.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
<input type="file" name="srcImg" size="60">
<input type="submit" value="submit">
</form>

PHP page (Photo.php):
PHP Code:

<?php
foreach($_REQUEST as $K => $V){
$$K = $V;
}

$root_dir = "accounts";

if(isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH']>2097152){
$action = 'Photo.php?error… FAILED, file is too large!';
header("Location: $action");
die();
}

if($srcImg_type == "image/x-png"
|| $srcImg_type == "image/png"
|| $srcImg_type == "image/gif"
|| $srcImg_type == "image/gif"
|| $srcImg_type == "image/pjpeg"
|| $srcImg_type == "image/jpeg"){
}else{
$action = 'Photo.php?error… FAILED, is not a jpg, gif or png file!';
header("Location: $action");
die();
}

$txtname = strtolower(basename($srcImg));

$result = @move_uploaded_file($srcImg_tmp, $txtname);

if(!file_exists($root_dir)){
mkdir($root_dir);
chmod($root_dir, 0777);
}

$getProfileFile = $root_dir."/".$txtname;

copy($txtname,$getProfileFile);

@unlink($txtname);
?>

When I try to preview my script locally, it says “The page isn’t redirecting properly”. How to get the code run correctly? Please advice.:frowning:

There is so much wrong here…first the foreach at the top with “_REQUEST” you should not be doing that or be using _REQUEST in that way. Next is the way the you are determining the type of the file. That is quite bad. Lots of bad things going on here…

Please advice how should I corrected my code so it would work fine, I am quite new to php and this is my 1st project on it. Thanks in advance.