Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > alt.comp.lang.php > #5
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Newsgroups | alt.comp.lang.php |
| Subject | Re: PHP/AJAX/HTML: del files with php function and onclick event |
| Date | 2016-01-27 07:17 +0100 |
| Message-ID | <dgr5o8F5emuU1@mid.individual.net> (permalink) |
| References | <4be558c6-68d6-4270-9c98-6b9a874d9763@googlegroups.com> |
On 01/26/2016 12:51 PM, maurizio.romano.wtech@gmail.com wrote:
> Goodmorning everyone. (sorry 4 may bad english).
>
> I need to delete files and folder using the "cancel" button present in a form.
> The folder path is stored in a session variable $_SESSION['del_path_dir'].
> After reading several solutions, I am right at the end to use an asynchronous call via AJAX. (not familiar with AJAX).
> After several attempts I ask help to you; I can not understand where the problem lies.
> Here the following code:
>
> [[[FILE: btncftrsm.php]]]
> <?php
> session_start();
> ?>
> <html>
> <head>
>
> <script type="text/javascript" src="../jquery/external/jquery/jquery.js"></script>
>
> <script type="text/javascript">
> function DelData()
> {
> var PathDel=$("#Path2Del").val();
> $.ajax({
> type:'POST',
> url:'deltmpfiles.php',
> data:PathDel,
> success: function(response)
> {
> rrmdir(PathDel);
> }
> });
> }
You need to read more about ajax, maybe start with
http://blog.teamtreehouse.com/beginners-guide-to-ajax-development-with-php
You need to define the post variable name for your PathDel.
> </script>
> </head>
> <body>
> <div class="container">
> <div class="row">
> <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
> <form method="post" action="conferma_2_0.php">
> <input type="hidden" name="confermato" value="true">
> <input type="hidden" name="Path2Del" id="Path2Del" value="<? echo $_SESSION['del_path_dir']?>" />
> <div class="row">
> <div class="col-xs-6 col-sm-6 col-md-6">
> <input type="button" onClick="DelData()" value="Annulla e Modifica" id="Annulla e Modifica" class="btn btn-primary btn-block btn-lg" tabindex="1">
> </div>
> <div class="col-xs-6 col-sm-6 col-md-6">
> <input type="submit" value="Conferma e Trasmetti" class="btn btn-primary btn-block btn-lg" tabindex="2">
> </div>
> </div>
> </form>
> </div>
> </div>
> </div>
> </body>
> </html>
>
>
> [[[FILE: deltmpfiles.php]]]
> <?php
>
> echo "SUCCESS";
Don't echo success, use header() to send http result codes, 200 for
success and 400 for fail, but do not do that until you have actually
done something.
>
> function rrmdir($strPATH)
> {
> if (is_dir($strPATH))
> {
> $objects = scandir($strPATH);
> foreach ($objects as $object)
> {
> if ($object != "." && $object != "..")
> {
> if (filetype($strPATH."/".$object) == $strPATH) rrmdir($strPATH."/".$object); else unlink($strPATH."/".$object);
> }
> }
> reset($objects);
> rmdir($strPATH);
> }
> echo "<script type=\"text/javascript\" charset=\"utf-8\">window.self.close()</script>";
this will not be executed on the ajax calling page.
> }
>
> /*
> $percorso = $_POST['percorso'];
> rrmdir($percorso);
> */
uncomment this, otherwise nothing will happen
> ?>
--
//Aho
Back to alt.comp.lang.php | Previous | Next — Previous in thread | Find similar
PHP/AJAX/HTML: del files with php function and onclick event maurizio.romano.wtech@gmail.com - 2016-01-26 03:51 -0800 Re: PHP/AJAX/HTML: del files with php function and onclick event "J.O. Aho" <user@example.net> - 2016-01-27 07:17 +0100
csiph-web