I need to delete a file using php function and then redirected the page to another one.

I tried with this code :
-----------------------------------------

delete("$file");
function delete($file){
unlink ($file);
header("Location: npp.php");
}

Works fine in my local host but the following error coming when upload to server : Cannot modify header information - headers already sent by (output started at /home/mysite/public_html/test/np.php:6) in /home/mysite/public_html/test/np.php on line 7 The permission of the directory is 777 and i tried my level best...

Please help me
Thanks in advance

It seems, as if you can't unlink the file. Try to write an @ before unlink (eg @unlink()). That makes the PHP engine not to print the error occured.
I can't tell you, why you don't have the permission to unlink the file but at least the execution of your script will be fine.

hi,

the unlinking is happening fine. the problem is headers are already sent so u cannot use header(Location:xxx.php). my shortcut to the problem is this. use javascript to redirect to the new page. do something like this echo "<script>window.location.href='abc.php'</script>";

now put this line where u have the header(Location: ) line and it will work hopefully.

hope this helps :)

Hi ! please try the following code:

Write "ob_start()" at the start of the page and run the script again. It prefer header rather than echo. Best of luck

Thanks for your valuable reply... Works great for me .... Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.