Laravel应用无文件删除权限,但单独PHP文件可删除的问题求助
Laravel应用删除文件权限异常问题
在服务器上运行Laravel应用时遇到权限问题:应用内无法删除指定文件,但单独编写PHP文件调用unlink($file);却能成功删除该文件。
文件及文件夹权限信息
文件信息:
-rw-r--r-- 1 user1 user1 27979 Dec 18 2021 myfile.pdf
文件夹(/storage/customfolder/)信息:
drwxrwxr-x 2 user1 user1 4096 Sep 26 12:32 customFolder
应用内尝试删除的代码
if (File::exists($path)) { if(File::delete($path)) { /// 文件已删除,成功 } }
已完成的权限及用户检查
// 检查当前用户 get_current_user(); => "user1" // 检查文件是否存在 file_exists('/******/shared/storage/customfolder/myfile.pdf') => true // 检查文件是否可写 is_writable('/******/shared/storage/customfolder/myfile.pdf') => false // 检查文件权限 substr(sprintf('%o', fileperms('/******/shared/storage/customfolder/myfile.pdf')), -4); => 0644 // 检查文件所有者 posix_getpwuid(fileowner('/******/shared/storage/customfolder/myfile.pdf')) => [ "name" => "user1", .... ] // 检查文件夹权限: substr(sprintf('%o', fileperms('/******/shared/storage/customfolder/')), -4); 0775 // 检查文件夹所有者 posix_getpwuid(fileowner('/******/shared/storage/customfolder/')) => [ "name" => "user1", .... ]
其他测试结果
- 在Laravel应用内直接调用
unlink删除:
unlink('/******/shared/storage/customfolder/myfile.pdf') => false
- 单独运行以下PHP文件可成功删除:
<?php $file = "/******/shared/storage/customfolder/myfile.pdf"; echo file_exists($file); if (file_exists($file)) { echo unlink($file); }
请问有人知道问题原因吗?非常感谢!
内容的提问来源于stack exchange,提问作者Op_Je_Plaatsman
相关产品推荐
相关产品推荐

