According to me this script should replace the image that already exist in the artist named folder but instead of replacing image with same username it is giving error. Else script is running successfully. It is uploading images but not replacing image with existing username.
<?
if(isset($POST["submit"]))
{ $type=$FILES["photo"]["type"];
if($type=="image/jpg"||$type=="image/jpeg"||$type=="image/pjpeg"||$type=="image/gif"||$type=="image/png")
{
if($FILES["photo"]["size"]<=500*1024)
{
$username=$POST["username"];
move_uploaded_file($FILES["photo"]["tmp_name"],"artist/".$FILES["photo"]["name"]);
$ext=substr($FILES["photo"]["name"],strpos($FILES["photo"]["name"],"."));
rename("artist/".$_FILES["photo"]["name"],"artist/$username$ext");
$msg="Saved";
} else $msg="Size limit Exceed";
} else $msg="Invalid Format";
}
?>
<html>
<head>
<title>
</title>
</head>
<body>
<form action="sankalpfile.php" method="post" enctype="multipart/form-data" name="form1">
<table width="500" border="0" align="center">
<tr>
<td>username</td>
<td><input type="text" name="username" id="username"></td>
</tr>
<tr>
<td>pics</td>
<td><input type="file" name="photo" id="photo">
max 500 kb</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Submit"></td>
</tr>
<tr>
<td> </td>
<td><?=$msg ?></td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>