NOTE: this is not supported at this timem. Please use newer code, like https://github.com/icewind1991/SMB.
Recently, we had a need to retrieve and put files onto a Windows server from a Linux box. I looked around for a good way to access samba or Windows file servers from within PHP, and I didn’t find anything promising. There’s Victor Verela’s smbwebclient, but it’s really more than I was looking for, as it provides a full web gateway to the SMB server. You could probably pull out his samba class and use that standalone, but it wasn’t quite what I was looking for.
I whipped up a simple PHP library based around the smbclient command-line executable. It isn’t very efficient for performing lots of operations, but if you only need to move a few files around, it’s very convenient to use.
Here’s an example of it in use:
$smbc = new smbclient ('//10.0.1.1/example', 'exampleuser', 'examplepassword');
if (!$smbc->get ('path/to/desired/file.txt', '/tmp/localfile.txt'))
print "Failed to retrieve file:\n";
print join ("\n", $smbc->get_last_stdout());
print "Transferred file successfully.";
Get the code here: https://gist.github.com/jpriebe/293aec9ba37e1d5c0570b757aab9aa74