Click to See Complete Forum and Search --> : Deleting image with JavaScript


harevik85
03-12-2008, 05:20 AM
I want to click on the image and delete it with Javascript, but it doesn't do:(

---------------------------------

<script language="JavaScript" type="text/javascript">
function funcClick(del)
{
if(isset($_get['del']))
{
if(file_exists($_get['del']))
unlink($_get['del']);
}
}
</script>

------------------------------------------

echo "<a href=\"adfsca.php&del=$subdir/$file\" onClick=\"funcClick()\"><img src=\"$subdir/$file\"></a> ";

TheRave
03-12-2008, 06:07 AM
You can't use PHP code in <script> tags.

PHP and Javascript are different languages.

PHP works on the server and Javascript works on the client.

Anything in <script> tags is on the client so cannot be PHP and should be Javascript (or an alternative client-side language).

If you need to delete a file on the server you can use the PHP unlink command but it has to be run on the server.

harevik85
03-13-2008, 04:38 AM
Thank you very much, I didn't understand what was the matter.