How can I delete a file using php? Using a linux server (if that matters).
Thanks for any help
Do I need to open the file before I can delete it?
no, the demo unlink code just shows a range of possibilities for its use
you can just unlink the file
but it is good to check if exists
Okay thanks, presumably if it doesn't exitst I'd have
$fh = fopen('test.html', 'a') or die("Failed");
You should check if the file you want to delete is existed. Try to use the file_exists function so your code would be like that:
if (file_exists('test.html')) unlink('test.html'); else echo "The file does not exist";
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.