Ciao gente, ho un po' di problemini con Jquery e PHP.
Quello che voglio fare è cancellare un immagine dal server alla pressione di un tag <a>. Un poco quello che accade a questo link ma al posto di un semplice commento ho un immagine.
Credo di aver fatto un poco di casino con il codice... Qualcuno mi sa dare qualche dritta su come passare le variabili da Jquery a PHP e vice versa?
JQuery
PHP (delete.php)codice:$(document).ready(function() { $('#load').hide(); }); $(function() { $(".delete").click(function() { $('#load').fadeIn(); var container = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; var name = $(this).parent().attr("title"); $.ajax({ type: "GET", url: "delete.php", data: 'string', cache: false, success: function(){ container.slideUp('slow', function() {$(this).remove();}); $('#load').fadeOut(); } }); $.ajax({ method:'GET', url: "delete.php", data:'name', success:function(response){ if (response === 'deleted') { alert('Deleted !!'); }else{ document.write(name); } } }); return false; }); });
HTMLCodice PHP:if (isset($_GET['name']))
{
if (unlink($_GET['name']))
{
echo 'deleted';
}else{
echo "The file ".$_GET['name']." was not deleted";
}
}else {
echo "The name of the file was not set!";
}
echo $_GET['id'];
Codice PHP:$dirname = "../images/portraits";
$images = scandir($dirname);
$ignore = Array(".", "..", ".DS_Store");
$count=1;
foreach($images as $img){
if (!in_array($img, $ignore)) {
if(!strripos($img, "_t")){
echo "<div title='$dirname/$img' class='thumb'>$img[url='#']x[/url]
<div class='clear'></div>[img]$dirname/$img[/img]</div>";
}
}
}

Rispondi quotando