Page 1 of 1

GET_id not working in UnLink (delete file)

Posted: 06 Feb 2023, 21:57
by JanMolendijk
I searching for an hour for a solution; unlink seems not to work with GET id

Code: Select all

<?php   
$id = (int) $_GET['id'];

echo  $_GET['id'];

$file = fopen("'.$_GET['id'].'.txt","w");
echo fwrite($file,"Succesfully written document ticket);
fclose($file);

unlink("'.$_GET['id'].'.txt");
?>
Hope Coursesweb can help me out.

GET_id not working in UnLink (delete file)

Posted: 06 Feb 2023, 22:27
by JanMolendijk
Here is an answer `o god after 2 hours shame on me for this one`

Code: Select all

<?php
$file_pointer = $_GET[file].'.txt';
if (!unlink($file_pointer)) {
   echo ("File can’t be deleted!");
} else {
   echo ("File deleted!");
}
?>