How to determine if file is writable and deletable

This is a discussion on How to determine if file is writable and deletable within the PHP General forums, part of the PHP Programming Forums category; I need to determine if a file is truly deletable by a php script, Deleting permissions seem to be the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-07-2008
Al
 
Posts: n/a
Default How to determine if file is writable and deletable

I need to determine if a file is truly deletable by a php script, Deleting permissions seem to be
the same as writing, they probably have the same criteria.

is_writable() seems to virtually useless in most cases. It doesn't take into account the directory
ownership/permissions; which, best I can tell, is the real determining factor.

I've resorted to having to determine the directory's ownership and then compare the directory's
rights with the owner's and then the other ['world'].

E.g., Assume my script was loaded with ftp, so it's ownership is the site-name, and I want the scrip
to be able to determine if it can delete a file. Thus, the file in question must have its "other"
permissions include write.

Surely, there must be an easier way.

Thanks, Al........
Reply With Quote
  #2 (permalink)  
Old 05-07-2008
Aschwin Wesselius
 
Posts: n/a
Default Re: [PHP] How to determine if file is writable and deletable

Al wrote:
> I need to determine if a file is truly deletable by a php script,
> Deleting permissions seem to be the same as writing, they probably
> have the same criteria.
>
> is_writable() seems to virtually useless in most cases. It doesn't
> take into account the directory ownership/permissions; which, best I
> can tell, is the real determining factor.
>
> I've resorted to having to determine the directory's ownership and
> then compare the directory's rights with the owner's and then the
> other ['world'].
>
> E.g., Assume my script was loaded with ftp, so it's ownership is the
> site-name, and I want the scrip to be able to determine if it can
> delete a file. Thus, the file in question must have its "other"
> permissions include write.
>
> Surely, there must be an easier way.
>
> Thanks, Al........
>

Hi,

Maybe this is what you need:

http://nl.php.net/manual/en/function.fileperms.php
--

Aschwin Wesselius

/'What you would like to be done to you, do that to the other....'/

Reply With Quote
  #3 (permalink)  
Old 05-07-2008
Al
 
Posts: n/a
Default Re: [PHP] How to determine if file is writable and deletable

You are missing the point of my question. I don't have a problem reading the permissions. They do
not solely determine whether a file can be deleted.

Aschwin Wesselius wrote:
> Al wrote:
>> I need to determine if a file is truly deletable by a php script,
>> Deleting permissions seem to be the same as writing, they probably
>> have the same criteria.
>>
>> is_writable() seems to virtually useless in most cases. It doesn't
>> take into account the directory ownership/permissions; which, best I
>> can tell, is the real determining factor.
>>
>> I've resorted to having to determine the directory's ownership and
>> then compare the directory's rights with the owner's and then the
>> other ['world'].
>>
>> E.g., Assume my script was loaded with ftp, so it's ownership is the
>> site-name, and I want the scrip to be able to determine if it can
>> delete a file. Thus, the file in question must have its "other"
>> permissions include write.
>>
>> Surely, there must be an easier way.
>>
>> Thanks, Al........
>>

> Hi,
>
> Maybe this is what you need:
>
> http://nl.php.net/manual/en/function.fileperms.php

Reply With Quote
  #4 (permalink)  
Old 05-07-2008
robinv@gmail.com
 
Posts: n/a
Default Re: [PHP] How to determine if file is writable and deletable

On 07/05/2008, Al <news@ridersite.org> wrote:
> I need to determine if a file is truly deletable by a php script, Deleting
> permissions seem to be
> the same as writing, they probably have the same criteria.


You're not writing to the file, you're unlinking it from the
containing directory, so it's the directory's permissions that matter,
not the file's.

All you really need to do is check that the directory is_writable()

is_writable(dirname($filename));

-robin
Reply With Quote
  #5 (permalink)  
Old 05-07-2008
Thiago Pojda
 
Posts: n/a
Default RES: [PHP] How to determine if file is writable and deletable

If it's not, what else can? I got curious.


Regards,
Thiago Henrique Pojda

-----Mensagem original-----
De: Al [mailto:news@ridersite.org]
Enviada em: quarta-feira, 7 de maio de 2008 12:25
Para: php-general@lists.php.net
Assunto: Re: [php] How to determine if file is writable and deletable

You are missing the point of my question. I don't have a problem reading the
permissions. They do
not solely determine whether a file can be deleted.

Aschwin Wesselius wrote:
> Al wrote:
>> I need to determine if a file is truly deletable by a php script,
>> Deleting permissions seem to be the same as writing, they probably
>> have the same criteria.
>>
>> is_writable() seems to virtually useless in most cases. It doesn't
>> take into account the directory ownership/permissions; which, best I
>> can tell, is the real determining factor.
>>
>> I've resorted to having to determine the directory's ownership and
>> then compare the directory's rights with the owner's and then the
>> other ['world'].
>>
>> E.g., Assume my script was loaded with ftp, so it's ownership is the
>> site-name, and I want the scrip to be able to determine if it can
>> delete a file. Thus, the file in question must have its "other"
>> permissions include write.
>>
>> Surely, there must be an easier way.
>>
>> Thanks, Al........
>>

> Hi,
>
> Maybe this is what you need:
>
> http://nl.php.net/manual/en/function.fileperms.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Reply With Quote
  #6 (permalink)  
Old 05-07-2008
tedd
 
Posts: n/a
Default Re: [PHP] How to determine if file is writable and deletable

At 11:16 AM -0400 5/7/08, Al wrote:
>I need to determine if a file is truly deletable by a php script,
>Deleting permissions seem to be the same as writing, they probably
>have the same criteria.
>
>is_writable() seems to virtually useless in most cases. It doesn't
>take into account the directory ownership/permissions; which, best I
>can tell, is the real determining factor.
>
>I've resorted to having to determine the directory's ownership and
>then compare the directory's rights with the owner's and then the
>other ['world'].
>
>E.g., Assume my script was loaded with ftp, so it's ownership is the
>site-name, and I want the scrip to be able to determine if it can
>delete a file. Thus, the file in question must have its "other"
>permissions include write.
>
>Surely, there must be an easier way.
>
>Thanks, Al........



Perhaps touch might help.

http://nl.php.net/manual/en/function.touch.php

Cheers,

tedd


--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
Reply With Quote
  #7 (permalink)  
Old 05-07-2008
Richard Heyes
 
Posts: n/a
Default Re: [PHP] How to determine if file is writable and deletable

> Perhaps touch might help.

Touch my ass.

ROFLMAO

(I've been waiting for years to use that one)

--
Richard Heyes

+----------------------------------------+
| Access SSH with a Windows mapped drive |
| http://www.phpguru.org/sftpdrive |
+----------------------------------------+
Reply With Quote
  #8 (permalink)  
Old 05-07-2008
tedd
 
Posts: n/a
Default Re: [PHP] How to determine if file is writable and deletable

At 9:18 PM +0100 5/7/08, Richard Heyes wrote:
>>Perhaps touch might help.

>
>Touch my ass.
>
>ROFLMAO
>
>(I've been waiting for years to use that one)



It won't work?

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
Reply With Quote
  #9 (permalink)  
Old 05-07-2008
Richard Heyes
 
Posts: n/a
Default Re: [PHP] How to determine if file is writable and deletable

> It won't work?

No idea, it was just a rather poor play on words.

--
Richard Heyes

+----------------------------------------+
| Access SSH with a Windows mapped drive |
| http://www.phpguru.org/sftpdrive |
+----------------------------------------+
Reply With Quote
  #10 (permalink)  
Old 05-11-2008
Al
 
Posts: n/a
Default Re: How to determine if file is writable and deletable

I ended up using posix_access() which is what is_writeable() should be. is_writeable() is virtually
useless.

Al wrote:
> I need to determine if a file is truly deletable by a php script,
> Deleting permissions seem to be the same as writing, they probably have
> the same criteria.
>
> is_writable() seems to virtually useless in most cases. It doesn't take
> into account the directory ownership/permissions; which, best I can
> tell, is the real determining factor.
>
> I've resorted to having to determine the directory's ownership and then
> compare the directory's rights with the owner's and then the other
> ['world'].
>
> E.g., Assume my script was loaded with ftp, so it's ownership is the
> site-name, and I want the scrip to be able to determine if it can delete
> a file. Thus, the file in question must have its "other" permissions
> include write.
>
> Surely, there must be an easier way.
>
> Thanks, Al........

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:03 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0