-
-
Save devluis/9845996 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="es"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Eliminar archivo con PHP y jQuery Ajax</title> | |
<!-- Bootstrap--> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> | |
<!-- jQuery--> | |
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script> | |
$(document).on('ready', function() { | |
$('a').on('click', function(e) { | |
e.preventDefault(); | |
$.ajax({ | |
url: 'process.php', | |
type: 'post', | |
dataType: 'json' | |
}) | |
.done(function() { | |
alert("Eliminado correctamente!"); | |
}) | |
.fail(function() { | |
alert("Ha ocurrido un error"); | |
}) | |
.always(function() { | |
}); | |
}) | |
}) | |
</script> | |
<style> | |
body { | |
width: 30%; | |
margin: 30px auto; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Eliminar archivo con PHP y jQuery Ajax</h1> | |
<a herf="#" class="btn btn-primary">Eliminar archivo</a> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = 'imagen.png'; | |
$json; | |
if (is_file($file)) { | |
chmod($file,0777); | |
if(!unlink($file)) { | |
echo false; | |
} | |
echo $json['success'] = true; | |
} else { | |
echo false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment