php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70139 is_link or DirectoryIterator->isLink don't work
Submitted: 2015-07-26 10:12 UTC Modified: 2015-07-30 14:42 UTC
From: tomkrawc at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 5.5.27 OS: Windows 7 64bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tomkrawc at gmail dot com
New email:
PHP Version: OS:

 

 [2015-07-26 10:12 UTC] tomkrawc at gmail dot com
Description:
------------
Neighter is_link nor DirectoryIterator->isLink are not distinguish symlinks created with os command mklink. Os is showing them:

2015-07-26  09:23    <DIR>          .
2015-07-26  09:23    <DIR>          ..
2015-05-23  20:55    <DIR>          _backup
2015-05-23  20:55    <DIR>          _logi
2015-07-26  09:23    <DIR>          fileadmin
2015-07-26  08:39    <SYMLINKD>     typo3 [typo3_src\typo3]
2015-07-26  08:39    <SYMLINKD>     typo3_src [..\typo3_src-6.2.14]
2015-07-26  09:23    <DIR>          typo3conf
2015-07-26  09:23    <DIR>          typo3temp
2015-07-26  09:23    <DIR>          uploads
2015-05-24  10:12             5 199 .htaccess
2015-04-14  20:03               113 index.html
2015-07-26  08:39    <SYMLINK>      index.php [typo3_src\index.php]
2015-05-23  18:40                19 pi.php

My env is Win 7 x64, WAMP (Apache 2.4.9, PHP 5.5.12 Thread Safe).

Test script:
---------------
if ($handle = opendir($dir)) {
	echo "Directory handle: $handle\n";
	echo "Entries:\n";

	while (false !== ($entry = readdir($handle))) {
		
		if (is_link($dir . $entry)) {
			$strTarget = readlink($entry);
			echo '>>LINK<<: ' . $entry . ' => ' . $strTarget . "\n";
		}
		elseif (is_file($dir . $entry)) {
			echo 'File: ' . $entry . "\n";
		}
		elseif (is_dir($dir . $entry)) {
			echo 'Dir: ' . $entry . "\n";
		}
		else {
			echo "? - $entry\n";
		}
	}
	closedir($handle);
}


Expected result:
----------------
both of those methods should return true

Actual result:
--------------
both of those methods should return false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-28 23:39 UTC] cmb@php.net
-Status: Open +Status: Feedback -Package: Win32API related +Package: Filesystem function related -Assigned To: +Assigned To: cmb
 [2015-07-28 23:39 UTC] cmb@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

See also <http://sscce.org/>.
 [2015-07-29 00:08 UTC] requinix@php.net
Wrote this and my Win 8.1 with PHPs 5.4.29, 5.5.13, 5.6.11 don't reproduce: is_file says no, is_dir and is_link say yes.

Note that you will probably need an elevated command prompt to run mklink.

<?php

$tempnam = tempnam(sys_get_temp_dir(), "php");
unlink($tempnam); // tempnam created a file

// expecting to see "symbolic link created for %s <<===>> C:\"
// - /d to create a directory symlink
// - /j to create a junction
passthru("mklink /d " . escapeshellarg($tempnam) . " C:\\");
clearstatcache();

if (file_exists($tempnam)) {
	echo "Created directory {$tempnam}\n";
	echo "- is_file: ", (is_file($tempnam) ? "yes" : "no"), "\n";
	echo "- is_dir:  ", (is_dir($tempnam) ? "yes" : "no"), "\n";
	echo "- is_link: ", (is_link($tempnam) ? "yes" : "no"), "\n";
	rmdir($tempnam) or printf("Failed to remove directory\n");
} else {
	echo "Directory {$tempnam} does not exist\n";
}

?>
 [2015-07-29 05:16 UTC] tomkrawc at gmail dot com
-Status: Feedback +Status: Assigned
 [2015-07-29 05:16 UTC] tomkrawc at gmail dot com
I don't know what to say. Yesterday the script http://pastebin.com/6h1G6ku5 was creating such an output http://pastebin.com/Z4c4pUDs. Today it returns expected results. 

The code of @requinix results that way http://pastebin.com/3PxHQU30. So it is correct.

I don't know why it works today...
 [2015-07-30 14:29 UTC] tomkrawc at gmail dot com
-Status: Assigned +Status: Closed
 [2015-07-30 14:29 UTC] tomkrawc at gmail dot com
It locks it was problem with incorectly used clearstatcache() function.
 [2015-07-30 14:42 UTC] cmb@php.net
-Status: Closed +Status: Not a bug
 [2015-07-30 14:42 UTC] cmb@php.net
Okay, changing the status to not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 23:01:29 2024 UTC