如何跨 SMB 挂载进行 PHP 复制

发布于 2024-11-19 15:59:56 字数 773 浏览 2 评论 0原文

我有一个简单的脚本,可以将文件从一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

森林散布 2024-11-26 15:59:57

我将命令更改为:

copy('/media/folder/filename.txt','/tmp/filename.txt');

显然,处理 SMB 共享上的文件比我想象的要困难。该文件应在计算机重新启动时删除,或者可能定期删除,具体取决于系统设置。

I changed the command to:

copy('/media/folder/filename.txt','/tmp/filename.txt');

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.

半仙 2024-11-26 15:59:56
system("cp /media/folder/filename.txt /media/folder2/temp/filename.txt");

可能对你有用。

system("cp /media/folder/filename.txt /media/folder2/temp/filename.txt");

Might work for you.

狠疯拽 2024-11-26 15:59:56

听起来像是一个特定于权限和操作系统而不是 PHP 的问题.. 什么网络服务器?服务器运行的是什么?没人:没人? nobody:nobody 或 www-root:www-root 可以将数据读/写到您尝试访问的目录中吗?

sudo su - nobody

  • 可能无法工作,因为它很可能有一个 /bin/false shell,
  • nobody 可能不是正确的帐户.. 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

  • probably wont work as it will most likely have a /bin/false shell
  • nobody may not be the right account .. ps auxw | grep apache | awk {'print $1'} and see which user it is running as ... then try changing over to that account with sudo

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文