duanqian3464
duanqian3464
2011-07-10 02:19
浏览 114
已采纳

如何跨SMB安装进行PHP复制

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
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dqmg80654
    dqmg80654 2011-07-10 17:03
    已采纳

    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.

    点赞 评论
  • dscpg80066
    dscpg80066 2011-07-10 05:41

    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.

    点赞 评论
  • dongshou1856
    dongshou1856 2011-07-10 17:07
    system("cp /media/folder/filename.txt /media/folder2/temp/filename.txt");
    

    Might work for you.

    点赞 评论

相关推荐