Added the ability to edit and delete posts which includes uploading of images for the posts and managing those images
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Vendored
+27
@@ -3,6 +3,8 @@
|
||||
namespace api\utils;
|
||||
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
class imgUtils
|
||||
{
|
||||
@@ -40,4 +42,29 @@ class imgUtils
|
||||
|
||||
return array("imgLocation" => $targetFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a directory and all its contents
|
||||
* @param string $path - Path to the directory to delete
|
||||
*/
|
||||
public function deleteDirectory(string $path): void
|
||||
{
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path,
|
||||
RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
|
||||
|
||||
foreach ($iterator as $file)
|
||||
{
|
||||
if ($file->isDir())
|
||||
{
|
||||
rmdir($file->getPathname());
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink($file->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
rmdir($path);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user