Hi, it's been for a while i try just to delete a file when you delete a row on PhpGrid. No way. The thing is i'm using 'unlink' php function, and i need the name/path of the photo to delete in a row that was a photo as a file.
When you delete you have a '$e["on_delete"] = array("delete_client", null, true);' event and then you can make a function delete_client($data) to make actions when on_delete. The problem cames when i want to know the name of my photo; i try everything;
– $nfoto=$data["foto"];
– $nfoto=$data["params"]["foto"];
– foreach($data["params"] as &$d)…
No way to get the photo's name file from $data array. How can i get the nanme of the photo from the row that has been deleted (and phpgrid has no $e["js_on_deleted_row"] client side) ???? Please, thanks.
Hello,
In on_delete event, only the selected ID is passed from client to server.
You need to run additional query to get the uploaded file path from database and then unlink it.
It could be little overhead but currently grid work in this way.
Ok it's working, thank's, my code to delete photo on a row after event DELETE:
function delete_client($data)
{
$nfoto="";
$id=$data['ID'];
$consulta="SELECT foto FROM galerias WHERE ID='$id'";
$resultado = mysql_query($consulta);
while ($fila = mysql_fetch_array($resultado)){
$nfoto=$fila['foto'];
}
unlink($nfoto);
}