943,948 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 431
  • PHP RSS
Mar 30th, 2009
0

A confusing php problem

Expand Post »
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
Last edited by rajeesh_rsn; Mar 30th, 2009 at 11:40 am. Reason: mistake
Similar Threads
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
rajeesh_rsn is offline Offline
265 posts
since Sep 2008
Mar 30th, 2009
0

Re: A confusing php problem

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.
Reputation Points: 56
Solved Threads: 29
Posting Whiz in Training
sDJh is offline Offline
255 posts
since Aug 2005
Mar 30th, 2009
0

Re: A confusing php problem

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
Last edited by hooka85; Mar 30th, 2009 at 4:16 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hooka85 is offline Offline
3 posts
since Mar 2009
Mar 30th, 2009
0

Re: A confusing php problem

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
virk1711 is offline Offline
2 posts
since Oct 2008
Mar 30th, 2009
0

Thank you

Thanks for your valuable reply... Works great for me .... Thanks.
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
rajeesh_rsn is offline Offline
265 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help! Notice: Undefined index
Next Thread in PHP Forum Timeline: PHP Drop Down Box - Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC