简体   繁体   中英

How to PHP copy across SMB mount

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
system("cp /media/folder/filename.txt /media/folder2/temp/filename.txt");

Might work for you.

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'} ps auxw | grep apache | awk {'print $1'} 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM