hi guys,
i just want to create a javascript confirm script if the file will overwrite the current file with the same filename or with a file already existing.
if yes: ask to overwrite
if no: back to edit file page
function overwrite()
{
var r=confirm("The same file name existing. Overwrite File?")
if (r==true)
{
document.write("<?php
// is this possible?
?>");
alert("overwrite done");
}
else
{
alert("You pressed Cancel!")
}
}
</script>
$target = "files/";
$target = $target . basename($_FILES['upfile']['name']);
$vbasename = basename($_FILES['upfile']['name']);
if (empty($vbasename)) {
$query = "UPDATE tablefile SET
fld_title = '{$file_title}',
fld_tags = '{$content}',
fld_user = '{$vuser}',
fld_datetime = '{$vdatetime}'
WHERE ndex_fileid = {$id}";
$result = mysql_query($query);
if (mysql_affected_rows() == 1) {
$message = "<div class=\"alert alert-success\">The File was successfully updated.</div>";
} else {
$message = "<div class=\"alert alert-error\">The File could not be updated.</div>";
$message .= "<br />" . mysql_error();
}
}
if (!empty($vbasename)) { // IF THERE IS FILE TO UPLOAD
/* this script not working
echo "<script type='text/javascript'>test();</script>";
*/
$vrow = get_file_filepage($_GET['filepage']);
$query = "UPDATE tablefile SET
fld_title = '{$file_title}',
fld_tags = '{$content}',
fld_user = '{$vuser}',
fld_datetime = '{$vdatetime}',
fld_filename = '{$vbasename}',
fld_filetype = '{$vfiletype}',
fld_filesize = '{$vfilesize}'
WHERE ndex_fileid = {$id}";
if(!mysqli_query($con, $query)){
printf('Error ' . mysqli_error($con));
}
$result = mysql_query($query);
move_uploaded_file($_FILES["upfile"]["tmp_name"],"server/php/files/" . $_FILES["upfile"]["name"]);
$message = "<div class=\"alert alert-success\">New File: $vbasename, succesfully updated.</div>";
}