Diskuse

Téma: hromadný unlink

Zdravim,
chci se zeptat, jak udelat hromadny unlink pri hromadnem mazani z mysql.
/*--- Mazání ---*/
if (isset($_POST['mazat'], $_POST['selected'])) {
$selected = array_keys($_POST['selected']);
$mazani = array();
foreach ($selected as $id) {
if (!is_numeric($id)) continue;
$mazani[] = "`id` = $id";}
$mazani = implode(' OR ', $mazani);
mysql_query ("DELETE FROM `"._mysql_prefix."-download` WHERE " . $mazani);
//unlink($mazani);
}

$output.="<fieldset><legend>".$_lang['xxl.admin.download.manager.delete']."</legend>";
$output.="<form action='' method='post' name='mazat'><table><tr>";
$output.="<td class=\"rpad\">&nbsp;</td>";
$output.="<td class=\"rpad\"><strong>".$_lang['xxl.admin.download.manager.type']."</strong></td>";
$output.="<td class=\"rpad\"><strong>".$_lang['xxl.admin.download.manager.link_down']."</strong></td>";
$output.="<td class=\"rpad\"><strong>".$_lang['xxl.admin.download.manager.ratted_num']."</strong></td>";
$output.="<td class=\"rpad\"><strong>".$_lang['xxl.admin.download.manager.anchor_html']."</strong></td>";
$output.="<td class=\"rpad\"><strong>".$_lang['xxl.admin.download.manager.hcm']."</strong></td>";
$output.="<td class=\"rpad\"><strong>".$_lang['xxl.admin.download.manager.hcm.not_public']."</strong></td>";

/*--- Sestavení ---*/
$vysledek = mysql_query("SELECT *,ID FROM `"._mysql_prefix."-download`");
while ($zaznam = mysql_fetch_array($vysledek)) {
$cesta = $zaznam["cesta"];
$stazeno = $zaznam["stazeno"];
$id = $zaznam["id"];
$output.="<tr><td class=\"rpad\"><input type='checkbox' name='selected[$id]' /></td>
<td class=\"rpad\">".$cesta."</td>
<td class=\"rpad\"> <a href='"._url."/download.php?dl=".$id."'>".$_lang['xxl.admin.download.manager.download']."</a></td>
<td class=\"rpad\"><strong>".$stazeno ." x</strong></td>
<td class=\"rpad\">&lt;a href=&quot;"._url."/download.php?dl=".$id."&quot;&gt;&lt;/a&gt;</td>
<td class=\"rpad\">[hcm]custom,downloadpublic,".$id."[/hcm]</td>
<td class=\"rpad\">[hcm]custom,downloadnotpublic,".$id."[/hcm]</td>
</tr>";}

$output.="<tr><td><input type='submit' name='mazat' value='Smazat' onclick='return _sysConfirm();' /></td></tr></form></table>
</fieldset>";

if ($mazani) {
$output.=_formMessage(1, "".$_lang['xxl.admin.download.manager.delete.ok']."");}
postZaslat odpověď
Mam to naznacene zapoznamkovanim, ale nejde to.
Diky :)
Mas prakticky 2 moznosti:
1. Odesles pres hidden inputy pole cest. Po odeslani ho projedes pres foreach s kontrolou jestli se id nachazi v poli selected.

2. Po odeslani das druhy sql dotaz ktery podle selected pole vytahne cesty z db

Osobne bych asi volil cestu 1 nejak takhle:
ve formu :$output.="<tr><td class=\"rpad\"><input type='checkbox' name='selected[$id]' /><input type='hidden' name='path[".$id."]' value='".$cesta."'></td>a pak po odeslani:if (isset($_POST['mazat'], $_POST['selected'])) {
$folder = "../upload/download";
foreach ($_POST['path'] as $key=>$value) {
if (in_array($key,$_POST['selected'])){unlink($folder.'/'.$value);}
}
mysql_query ("DELETE FROM `"._mysql_prefix."-download` WHERE id in(".implode(',',$_POST['selected']).")");
}
Bohužel nejde. 😞
OK, tak az budu mit chvily, tak to zkusim, psal jsem to z hlavy.