如何跨 SMB 挂载进行 PHP 复制
我有一个简单的脚本,可以将文件从一个 SMB 安装复制到另一个。源文件系统相同,但Web服务器不同。我使用 PHP 来处理该文件,方法是将其复制到临时目录,然后对其执行其他任务。此设置在某个时间点可以正常工作,但似乎不再正常工作。有人能指出我正确的方向吗?
fstab 挂载:
//192.168.0.x/share /media/folder smbfs username=user,password=mypass
//192.168.0.x/share2 /media/folder2 smbfs username=user,password=mypass
php 代码:
copy('/media/folder/filename.txt','/media/folder2/temp/filename.txt');
错误:
Warning: copy(/media/folder2/temp/filename.txt): failed to open stream: Permission denied in /www/myphp.php on line xx
文件夹权限(不是挂载,而是文件服务器上的源文件夹) ):
/media/folder = 777
/media/folder2/temp = 777
I have a simple script which copies a file from one SMB mount to another. The source file system is the same, but the web server is different. I'm using PHP to process the file by copying it to a temp directory, then performing additional tasks on it. This setup was working at one point in time but it seems that it's no longer working correctly. Can someone point me in the right direction?
fstab mounts:
//192.168.0.x/share /media/folder smbfs username=user,password=mypass
//192.168.0.x/share2 /media/folder2 smbfs username=user,password=mypass
php code:
copy('/media/folder/filename.txt','/media/folder2/temp/filename.txt');
Error:
Warning: copy(/media/folder2/temp/filename.txt): failed to open stream: Permission denied in /www/myphp.php on line xx
Folder permissions (not the mount, but the source folder on the fileserver):
/media/folder = 777
/media/folder2/temp = 777
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将命令更改为:
显然,处理 SMB 共享上的文件比我想象的要困难。该文件应在计算机重新启动时删除,或者可能定期删除,具体取决于系统设置。
I changed the command to:
Apparently it's more difficult to process files on an SMB share than I thought. The file should be removed when the computer's rebooted, or possibly at regular intervals, depending on the system setup.
可能对你有用。
Might work for you.
听起来像是一个特定于权限和操作系统而不是 PHP 的问题.. 什么网络服务器?服务器运行的是什么?没人:没人? nobody:nobody 或 www-root:www-root 可以将数据读/写到您尝试访问的目录中吗?
sudo su - nobody
/bin/false
shell,ps auxw | grep 阿帕奇 | awk {'print $1'}
并查看它以哪个用户身份运行...然后尝试使用sudo
切换到该帐户在 PHP 有权写入文件之前,您需要确保网络服务器运行的用户...有权读取/写入您正在尝试
复制
的目录。sounds like a question that is specific to permissions and the OS and not PHP .. what webserver? what is the server running as? nobody:nobody? can nobody:nobody or www-root:www-root read/write data into the directories you are trying to access?
sudo su - nobody
/bin/false
shellps auxw | grep apache | awk {'print $1'}
and see which user it is running as ... then try changing over to that account withsudo
Before PHP can have access to write the files, you need to ensure the user which the webserver is running as ... has access to read/write to the directory you are trying your
copy
on.