very very strange problem with unlink

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

very very strange problem with unlink

Post by pelegk2 »

i have this code :

Code: Select all

for($i=0;$i<count($delLst); )
      unlink($delLst&#1111;$i++]);
always when the loop is at its last index
it can't delete the file that is in that index,not metter what the file!!!
i tried iffrent cobmination and every time the same problem!
always the last file isnt deleted and i get a permission denied warning!
why is that?
thnaks in advance
peleg
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

it is because apache or whoever executes the php code is not allowed to delete the files.



use php tags instead of code ;)

imho cleaner ways to write that loop are:

Code: Select all

foreach($delLst as $file)
{
  unlink($file);
}

Code: Select all

for ($i = 0; $i < count($delLst); ++$i)
{
  unlink($delLst[$i];
}
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

well

Post by pelegk2 »

you wrote :
it is because apache or whoever executes the php code is not allowed to delete the files
well its not thep roblem!!!!
beacuse f for example the last file iss 3333.txt
and it dosent delete it
i add a new file called 44444.xt
and now 4444.txt isnt being deleted!!!!!

if it matters i am working with apache 2.0.46 and php 4.3.2 on win 2000
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

post the actual error code
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

ok found it
ihave left a fopen() iwth a pointer to the file beacuse of that1
Post Reply