|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35980 touch() works on files but not on directories (on Linux this works perfectly)
Submitted: 2006-01-12 16:17 UTC Modified: 2009-03-04 10:03 UTC
From: pavel dot hlousek at gmail dot com Assigned: pajoye
Status: Closed Package: Filesystem function related
PHP Version: 5.2.4 (?) OS: win32 only
Private report: No CVE-ID:
 [2006-01-12 16:17 UTC] pavel dot hlousek at gmail dot com
<?php touch('non-existing-file'); ?> - Correct. Creates a new file.

<?php touch('existing-file'); ?> - Correct. Changes file's mtime.

<?php touch('existing-directory'); ?> - Wrong on Win2K. Does not change directory's mtime. Correct on Linux. I did not test any other Win32 platforms. Filesystem: NTFS. The user running the script owns 'existing-directory'. safe_mode=Off.

Reproduce code:
<?php touch('existing-directory'); ?>

Expected result:
Change mtime of an existing directory.

Actual result:
Utime failed: Permission denied in <fullpath/to/existing-directory> on line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-14 10:58 UTC]
"Permission denied" means that the user which the script was run as does not have permissions to do it. It's not a PHP bug.
 [2006-01-15 00:15 UTC]
This is a bug in microsoft's utime implementation.
However, Perl is able to workaround this bug with SetFileTime(). I'll see if I can cook a nice patch.
 [2006-01-15 18:30 UTC]

Note: it includes a function that was adapted from Perl 5 (win_filetime_from_time). The Perl code is distributed under GPL (and that file is (c) 1995 Microsoft Corporation), so I'm not sure if the code can go in. That function just converts a time_t into microsoft's format.
 [2006-04-15 21:16 UTC]
Sara, could you plz check the patch out? Thanks.
 [2006-04-16 03:03 UTC]
I'll try looking for unencumbered information to develop a fix that avoids GPL licensing complications first.

If it's indeed the result of a bug in the microsoft OS implementation there should be sufficient information out there to develop a fix that doesn't involve reusing restrictively licensed code.
 [2007-09-05 13:54 UTC]
Sara, what's the status on this? (version was weird, never saw this before checking what people have now invented as version..)
 [2008-07-13 16:11 UTC]
Nuno, as Sara isn't doing anything anymore, I guess it's up to you now to fix this..?
 [2009-03-04 10:03 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sat Feb 25 11:01:48 2017 UTC