Fix document upload from ckeditor elfinder manager

pull/2944/head
Julio Montoya 6 years ago
parent b1fed970ed
commit e2e0e1e794
  1. 2
      main/document/document.php
  2. 19
      main/inc/lib/document.lib.php
  3. 19
      main/inc/lib/fileUpload.lib.php
  4. 45
      src/CoreBundle/Component/Editor/Driver/CourseDriver.php

@ -41,6 +41,7 @@ $parent_id = null;
$lib_path = api_get_path(LIBRARY_PATH);
$actionsRight = '';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$allowUseTool = false;
$em = Database::getManager();
$charset = 'utf-8';
@ -317,6 +318,7 @@ switch ($action) {
false,
$sessionId
);
if ($sessionId != 0 && !$document_data) {
// If there is a session defined and asking for the document *from
// the session* didn't work, try it from the course (out of a

@ -2873,6 +2873,7 @@ class DocumentManager
* @param string $fileKey
* @param bool $treat_spaces_as_hyphens
* @param int $parentId
* @param $content
*
* @return CDocument|false
*/
@ -2887,7 +2888,8 @@ class DocumentManager
$show_output = false,
$fileKey = 'file',
$treat_spaces_as_hyphens = true,
$parentId = 0
$parentId = 0,
$content = null
) {
$course_info = api_get_course_info();
$sessionId = api_get_session_id();
@ -2915,7 +2917,8 @@ class DocumentManager
$sessionId,
$treat_spaces_as_hyphens,
$fileKey,
$parentId
$parentId,
$content
);
// Showing message when sending zip files
@ -6475,14 +6478,14 @@ class DocumentManager
$provider = 'sonata.media.provider.image';
}
error_log($provider);
//error_log("Provider: $provider");
$media->setProviderName($provider);
$media->setEnabled(true);
if ($content instanceof UploadedFile) {
//error_log('UploadedFile');
$file = $content;
error_log('1');
$media->setSize($file->getSize());
} else {
// $path points to a file in the directory
@ -6494,16 +6497,16 @@ class DocumentManager
$media->setHeight($size[1]);
}
$file = $realPath;
error_log('2');
//error_log("file exists: $realPath");
} else {
// We get the content and create a file
$handle = tmpfile();
fwrite($handle, $content);
$file = new \Sonata\MediaBundle\Extra\ApiMediaFile($handle);
$file->setMimetype($media->getContentType());
error_log($file->getSize());
error_log($media->getContentType());
error_log('3');
/*error_log('We get content and create a file from handle');
error_log('Size: '.$file->getSize());
error_log('Content type: '.$media->getContentType());*/
}
}

@ -3,6 +3,7 @@
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CDocument;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* FILE UPLOAD LIBRARY.
@ -106,7 +107,7 @@ function process_uploaded_file($uploaded_file, $show_output = true)
// The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
// Not used at the moment, but could be handy if we want to limit the size of an upload
// (e.g. image upload in html editor).
$max_file_size = intval($_POST['MAX_FILE_SIZE']);
$max_file_size = (int) $_POST['MAX_FILE_SIZE'];
if ($show_output) {
Display::addFlash(
Display::return_message(
@ -221,6 +222,7 @@ function process_uploaded_file($uploaded_file, $show_output = true)
* @param bool $treat_spaces_as_hyphens
* @param string $uploadKey
* @param int $parentId
* @param $content
*
* So far only use for unzip_uploaded_document function.
* If no output wanted on success, set to false.
@ -243,7 +245,8 @@ function handle_uploaded_document(
$sessionId = null,
$treat_spaces_as_hyphens = true,
$uploadKey = '',
$parentId = 0
$parentId = 0,
$content = null
) {
if (!$userId) {
return false;
@ -361,11 +364,12 @@ function handle_uploaded_document(
$documentRepo = Container::$container->get('Chamilo\CourseBundle\Repository\CDocumentRepository');
$document = $documentRepo->find($docId);
$request = Container::getRequest();
$content = $request->files->get($uploadKey);
if (is_array($content)) {
$content = $content[0];
if (!($content instanceof UploadedFile)) {
$request = Container::getRequest();
$content = $request->files->get($uploadKey);
if (is_array($content)) {
$content = $content[0];
}
}
// What to do if the target file exists
@ -511,7 +515,6 @@ function handle_uploaded_document(
);
}
} else {
error_log($filePath);
// Put the document data in the database
$document = DocumentManager::addDocument(
$courseInfo,

@ -3,6 +3,9 @@
namespace Chamilo\CoreBundle\Component\Editor\Driver;
use Chamilo\CoreBundle\Framework\Container;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Class CourseDriver.
*
@ -82,7 +85,7 @@ class CourseDriver extends Driver implements DriverInterface
$courseCode = $this->connector->course->getCode();
$alias = $courseCode.' '.get_lang('Documents');
$userId = $this->connector->user->getId();
// var_dump($this->getCourseDocumentSysPath());exit;
$config = [
'driver' => 'CourseDriver',
'path' => $this->getCourseDocumentSysPath(),
@ -296,22 +299,20 @@ class CourseDriver extends Driver implements DriverInterface
}
if (!empty($_FILES)) {
$files = $_FILES['upload'];
$fileList = [];
foreach ($files as $tempName => $array) {
$counter = 0;
foreach ($array as $data) {
$fileList[$counter][$tempName] = $data;
$counter++;
}
}
$resultList = [];
$request = Container::getRequest();
$fileList = $request->files->get('upload');
/** @var UploadedFile $file */
foreach ($fileList as $file) {
$globalFile = [];
$globalFile['files'] = $file;
$document = \DocumentManager::upload_document(
$globalFile,
$fileInfo = $file->getFileInfo();
$item = [
'files' => [
'tmp_name' => $fileInfo->getPathname(),
'error' => $file->getError(),
'size' => $file->getSize(),
],
];
\DocumentManager::upload_document(
$item,
$currentDirectory,
'',
'', // comment
@ -321,18 +322,10 @@ class CourseDriver extends Driver implements DriverInterface
false,
'files',
true,
0
$directoryParentId,
$file
);
}
exit;
/*\DocumentManager::addDocument(
$this->connector->course,
$realPath,
'file',
(int) $result['size'],
$result['name']
);*/
}
}

Loading…
Cancel
Save