mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-01-05 23:30:46 +01:00
Added an upload media task
This commit is contained in:
@@ -150,6 +150,30 @@ class AdminController
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function taskAddmedia()
|
||||
{
|
||||
$page = $this->admin->page(true);
|
||||
$config = $this->grav['config'];
|
||||
|
||||
if (!empty($_FILES)) {
|
||||
$tempFile = $_FILES['file']['tmp_name'];
|
||||
$targetName = $_FILES['file']['name'];
|
||||
|
||||
$fileParts = pathinfo($targetName);
|
||||
$fileExt = $fileParts['extension'];
|
||||
|
||||
// If not a supported type, return
|
||||
if (!$config->get("media.{$fileExt}")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Valid file type, so save it.
|
||||
$targetPath = $page->path();
|
||||
$targetFile = $targetPath.'/'.$targetName;
|
||||
move_uploaded_file($tempFile,$targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable plugin.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user