One way I find is that you can pass a value to url then fetch it inside php.
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var id = getParameterByName('id');
if(!id)
{
var id =window.confirm("Did You want to overwrite the file...");
window.location.href = "test.php?id="+id
}
In our case it is id, if id is set to true then execute else whatever you want to do.
$id = $_GET['id'];
if($uploadedby==$name && $id == true)
{
move_uploaded_file($file_loc,$folder.$file);
$sql="update pubfiles SET filename='$file',owner_name='$name',upload_time='$file_time',size='$file_size' WHERE content='$unique';";
$qry=mysql_query($sql,$conn);
if($qry>0)$check="yes";
}
Credit for url parsing in javascript:
How can I get query string values in JavaScript?