0

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

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by rajeesh_rsn
0

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.

0

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 :)

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.