php 的 rename 函数在什么情况下会输出 Operation not permitted 的错误,而不是警告?
基本环境
Ubuntu 16.04.1
apache 2.4
php 7.1.7
php 文件的根目录是通过 samba 挂载的一个 windows 机器下的目录
//192.168.44.1/dev/144 on /home/wwwroot type cifs (rw,nosuid,nodev,noexec,relatime,vers=default,cache=none,domain=,uid=0,forceuid,gid=0,forcegid,addr=192.168.44.1,file_mode=0777,dir_mode=0777,nounix,mapposix,rsize=1048576,wsize=1048576,echo_interval=60,actimeo=1)
目录本身是可以访问的……拥有所有rw权限,只是没有 x 权限
报错部分……
84: if(file_exists($targetPath))return true;
85: if (!$tran) return rename($fromPath, $targetPath);【此行】
[2018-03-26 09:44:45] local.ERROR: ErrorException: rename(/tmp/php2aXCEp,/home/wwwroot/cm/public_static/upload/user/1b/11384324d7be4098700a14ecfb418a.png): Operation not permitted in /home/wwwroot/cm/app/Helpers/FileReceiver.php:85
http://php.net/manual/en/func...
根据文档来讲的话,在版本 4.3.3 之后 rename 到不支持的文件系统上“可能”会产生一个警告……
但是现在的情况是这个函数直接就抛出了一个错误,但是文件却又复制成功了……
官方这文档下面也有几个遇到同样情况的仁兄【就是都被踩垫底了……】,虽然加个 @ 再重新 file_exists 基本就可以解决问题,不过这种情况是如何产生的?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
许久没有管这个事情……自问自答了……
翻了一下评论曰实际上是一个fat文件系统权限的问题……说是说不能叫做bug……但是总之就当个注意点吧……
参考ben at indietorrent dot org 的回答……
也就是复制到fat格式的文件系统上时会产生如此的错误……