PHP code example of isklv / smb-bundle
1. Go to this page and download the library: Download isklv/smb-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
isklv / smb-bundle example snippets
// application/ApplicationKernel.php
public function registerBundles()
{
$bundles = array(
new SMBBundle\SMBBundle()
);
}
$fileToUpload = __FILE__;
$server = $this->get('smb.server');
$share = $server->getShare('test');
$share->put($fileToUpload, 'example.txt');
$target = __DIR__ . '/target.txt';
$server = $this->get('smb.server');
$share = $server->getShare('test');
$share->get('example.txt', $target);
$server = $this->get('smb.server');
$shares = $server->listShares();
foreach ($shares as $share) {
echo $share->getName() . "\n";
}
$server = $this->get('smb.server');
$share = $server->getShare('test');
$content = $share->dir('test');
foreach ($content as $info) {
echo $name->getName() . "\n";
echo "\tsize :" . $info->getSize() . "\n";
}
$server = $this->get('smb.server');
$share = $server->getShare('test');
$fh = $share->read('test.txt');
echo fread($fh, 4086);
fclose($fh);
$server = $this->get('smb.server');
$share = $server->getShare('test');
$fh = $share->write('test.txt');
fwrite($fh, 'bar');
fclose($fh);
$server = $this->get('smb.server');
$server->setAuthParams('localhost', 'user0', 'user0');
$share = $server->getShare('test');
$fileToUpload = __FILE__;
if (Server::NativeAvailable()) {
$server = new NativeServer('localhost', 'test', 'test');
} else {
echo 'libsmbclient-php not available, falling back to wrapping smbclient';
$server = $server = $this->get('smb.server');;
}
$share = $server->getShare('test');
$share->put($fileToUpload, 'example.txt');