A confusing php problem

Reply

Join Date: Sep 2008
Posts: 140
Reputation: rajeesh_rsn is an unknown quantity at this point 
Solved Threads: 0
rajeesh_rsn rajeesh_rsn is offline Offline
Junior Poster

A confusing php problem

 
0
  #1
Mar 30th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 150
Reputation: sDJh is an unknown quantity at this point 
Solved Threads: 13
sDJh sDJh is offline Offline
Junior Poster

Re: A confusing php problem

 
0
  #2
Mar 30th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 3
Reputation: hooka85 is an unknown quantity at this point 
Solved Threads: 0
hooka85 hooka85 is offline Offline
Newbie Poster

Re: A confusing php problem

 
0
  #3
Mar 30th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2
Reputation: virk1711 is an unknown quantity at this point 
Solved Threads: 0
virk1711 virk1711 is offline Offline
Newbie Poster

Re: A confusing php problem

 
0
  #4
Mar 30th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 140
Reputation: rajeesh_rsn is an unknown quantity at this point 
Solved Threads: 0
rajeesh_rsn rajeesh_rsn is offline Offline
Junior Poster

Thank you

 
0
  #5
Mar 30th, 2009
Thanks for your valuable reply... Works great for me .... Thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC