Skip to content

Instantly share code, notes, and snippets.

@ashickur-rahman
Last active November 12, 2021 13:31
Show Gist options
  • Save ashickur-rahman/bdd57053057057a4a2554c4bc282335a to your computer and use it in GitHub Desktop.
Save ashickur-rahman/bdd57053057057a4a2554c4bc282335a to your computer and use it in GitHub Desktop.
php interface
<?php
//include __DIR__."/../vendor/autoload.php";
interface Network
{
public function checkExist($location);
public function createDir($location,$permission);
public function upload($path,$file);
public function delete($path);
}
class NetworkDrives
{
protected Network $network;
public function __construct(Network $network)
{
$this->network = $network;
}
public function drivesCheckExist($location)
{
return $this->network->checkExist($location);
}
public function drivesCreateDir($location,$permission="0755")
{
return $this->network->createDir($location,$permission);
}
public function drivesUpload($path,$file)
{
return $this->network->upload($path,$file);
}
public function drivesDelete($path)
{
return $this->network->delete($path);
}
}
class LocalDrive implements Network
{
public function checkExist($location)
{
if(file_exists($location))
{
return '1';
}
else
{
return "0";
}
}
public function createDir($location,$permission="0755")
{
if(mkdir($location,$permission,true))
{
return $location;
}
else
{
return 0;
}
}
public function upload($path,$file)
{
if(move_uploaded_file($path, $file))
{
return 1;
}
else
{
return 0;
}
}
public function delete($path)
{
if(is_dir($path))
{
if(rmdir($path))
{
return "1";
}
else
{
return 0;
}
}
elseif (is_file($path))
{
if(unlink($path))
{
return "1";
}
else
{
return 0;
}
}
}
}
$localFile=new NetworkDrives(new LocalDrive());
$localFile->drivesCreateDir("111/222/33");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment