How to delete a photo in deleted row

QuestionsHow to delete a photo in deleted row
Alex asked 6 years ago

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.

2 Answers
Abu Ghufran answered 6 years ago

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.

Alex answered 6 years ago

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);
}

Your Answer

4 + 9 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating / 5. Vote count:

We are sorry that this post was not useful for you!

Let us improve this post!