I am using the following script. it basically checks if the name of the file being uploaded already exists, if it does it should rename it to something else and upload it. So far it doesn't work. either it renames all files or when i try to open the file via webpage it says corrupt file.
Code:
$sql="SELECT filename FROM doc_u WHERE person_id= '$pid'";
$result=mysql_query($sql);
$query = mysql_query($sql) or die ("Error: ".mysql_error());
if ($result == "")
{
echo "";
}
echo "";
$rows = mysql_num_rows($result);
if($rows == 0)
{
print("");
}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{
$existing = $row['filename'];
print("");
}
}
if ( $filename === $existing ) {
$filename = $uniqueidgenerator.strrchr($_FILES['filename']['name'], ".");
} else {
$filename = $_FILES['filename']['name'];;
}
//After checking it will move the files
if(move_uploaded_file($_FILES['filename']['tmp_name'],$upload_path . $filename))
echo '';
else
echo '';