|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-01-27 21:38 UTC] lukyer at gmail dot com
Description:
------------
When samba drive is mapped in Windows, call to is_writable returns false on folders and files although these are actually writable.
is_readable seems working ok.
Test script:
---------------
echo is_writeable("Z://fdvtest"); // returns 0
file_put_contents("Z://fdvtest/file", "content"); // works fine
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
Cannot reproduce here: var_dump(is_writable('p:\tmp')); var_dump(file_put_contents('p:\tmp\hello.txt', 'hello')); this delivers bool(true) int(5) @lukyer please check what exactly is causing this behavior and provide some more data, so we can reproduce and debug. Thanks.Drive Z in my case is Samba mapped drive using "Map network drive" function in Windows Explorer. "tmp (\\192.168.0.15\bughunt)". Any other drives works as expected. Just network Samba drives are problematic. var_dump(is_writable('Z:\tmp')); var_dump(file_put_contents('Z:\tmp\hello.txt', 'hello')); output: bool(false) int(5)I believe I have this bug in my development environment. I am running PHP 5.6.22, 64-bit version, my workstation is Windows 10 Pro x64. I am developing in Visual Studio using the DevSense phptools plugin, this plugin debugs the code using xdebug and the built-in webserver of php.exe I have created the following test script: <?php var_dump(is_writable("//10.151.140.102/TestAlex/SubFolder1/")); var_dump(file_put_contents("//10.151.140.102/TestAlex/SubFolder1/Test.txt", "Testing...")); var_dump(is_writable("//127.0.0.1/c$/temp/SubFolder1/")); var_dump(file_put_contents("//127.0.0.1/c$/temp/SubFolder1/Test.txt", "Testing...")); ?> Which outputs: script1.php:2:boolean false script1.php:3:int 10 script1.php:4:boolean true script1.php:5:int 10 Note that the first line returns false However, I do have write permissions on the //10.151.140.102/TestAlex/SubFolder1/ folder. Also, the Test.txt file exists in that directory with the 'Tersting...' string. Note that am a member of the Administrators group on the 10.151.140.102 machine. I was surprised to see the is_writable() function returning true on the \\127.0.0.1\c$\... share, this I can not explain... This is going wrong on 2 different development machines (both running above mentioned configuration). On our test webserver, which runs Windows 2008 R2 x64, Apache 2.4.4 and php 5.6.16 the is_writable() function correctly sees the \\10.151.140.102\TestAlex\... path as writable and returns trueThis is not directly related to Samba. Accessing AD share from a machine not joined to domain produce similar results. Bottom line is: You MUST NOT make any decisions based on manual ACL inspection, if you are not the access control entity. I've had to namespace something to get my code going forward. <?php namespace Same\As\One\You\Use\Them\In; function is_readable($file) { if(file_exists($file) && is_file($file)) { $f = @fopen($file, 'rb'); if(fclose($f)) { return true; } } return false; } function is_writable($file) { $result = false; if(file_exists($file) && is_file($file)) { $f = @fopen($file, 'ab'); if(fclose($f)) { return true; } } return false; } ?>Hi, is_writable still not ok on directory with php 8.1.x on windows Example of workaround: function my_is_writable($file){ if (is_dir($file)) { $ldir = rtrim($file, '/\\'); //strip both forward and back slashes $Dir_my_is_writable = file_put_contents($ldir.'/dummyZER.txt', "hello"); unlink($ldir.'/dummyZER.txt'); if ($Dir_my_is_writable > 0) return true; else return false; } return is_writable($file); } Best regards.