Skip to content

Instantly share code, notes, and snippets.

@devluis
Forked from SoldierCorp/index.html
Created March 29, 2014 00:37
Show Gist options
  • Save devluis/9845996 to your computer and use it in GitHub Desktop.
Save devluis/9845996 to your computer and use it in GitHub Desktop.

Revisions

  1. @SoldierCorp SoldierCorp created this gist Mar 28, 2014.
    47 changes: 47 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    <!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>
    16 changes: 16 additions & 0 deletions process.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <?php
    $file = 'imagen.png';
    $json;

    if (is_file($file)) {
    chmod($file,0777);

    if(!unlink($file)) {
    echo false;
    }

    echo $json['success'] = true;
    } else {
    echo false;
    }
    ?>