Hi guys, I have a simple php script to upload file. I'm having some problem in creating confirmation before overwriting the file from new file upload.
Situation:
1. confirm() works if using file_exists BUT not overwrite the file or process the move_uploaded_file
assuming some tags are correct
uploadfile.php
<form enctype="multipart/form-data" action="addfile.php" method="POST" action="javascript:alert('success!');">
<td><label for="file">Choose File to Upload:</label></td>
<td>
<input type="file" name="upfile" id="upfile"> <br><br>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="hidden" name="fileuploaded">
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="submit" value="Add" class="pure-button pure-button-success" onclick="tellme();">
<!-- <input type="submit" name="submit" value="Add" class="confirmLink"> -->
<a href="index.php" ><button class="pure-button pure-button-secondary">Cancel</button></a>
</form>
addfile.php
<script type="text/javascript">
function tellme()
{
alert("New File Added Successfully.");
window.location = 'search.php';
}
function overwrite()
{
var r=confirm("Overwrite File?")
if (r==true)
{
alert("You pressed OK!")
window.location = 'search.php';
}
else
{
alert("You pressed Cancel!")
window.location = 'new_file.php';
}
}
</script>
if(!mysqli_query($con, $sql))
{
die('Error ' . mysqli_error());
}
if (file_exists("files/" . $_FILES['upfile']['name']))
{
echo "<script type='text/javascript'>
var answer = confirm(Overwrite? Y/N)
if (answer)
{
<?php move_uploaded_file($_FILES['upfile']['tmp_name'],$target); ?>
}
</script>";
}
else
{
move_uploaded_file($_FILES['upfile']['tmp_name'],$target);
echo "<script type='text/javascript'>tellme();</script>";
Thanks in advance! cheers!