I’ve been looking around and appearently the // if sucess should be executed when the file gets renamed:
if(rename("$filepath$oldfilename", "$filepath$filename")===true) { // if success }
Unfortunately, since this function renames the file even if another file is there with the same name, it’s always a success.
But yet worse…since another file with same name already exists, it somehow gets deleted…
Anyone know a way how to prevent this? And why this is happening?!
Additional info:
Im giving the user the opportunity to change the file name through a textarea, when it’s posted, the rename function will start:
if(rename("$filepath$oldfilename", "$filepath$filename")===true)
{
$WhatToUpdateQueryResult = mysql_query($WhatToUpdateQuery) or die ("query fout ". mysql_error() );
if ($WhatToUpdateQueryResult == 1)
{
$uploadmsg = "Document name successfully updated.<br/> From: $oldfilename <br/> To: $filename.";
}
}
else
{
$uploadmsg = "Can't update document. A file with the same name already exists.";
}
Note: As long I change the name to something which doesn’t already exists, it works fine. But still, it always ends up true.
You will have to make a function to check if filename already exists:
And put that function in your if statement.
Now it will be