diff --git a/main/document/upload.php b/main/document/upload.php index 01c98b6089..3c311f3aaa 100755 --- a/main/document/upload.php +++ b/main/document/upload.php @@ -2,33 +2,6 @@ /* For licensing terms, see /license.txt */ /** - * Main script for the documents tool. - * - * This script allows the user to manage files and directories on a remote http server. - * - * The user can : - navigate through files and directories. - * - upload a file - * - delete, copy a file or a directory - * - edit properties & content (name, comments, html content) - * - * The script is organised in four sections. - * - * 1) Execute the command called by the user - * Note: somme commands of this section are organised in two steps. - * The script always begins with the second step, - * so it allows to return more easily to the first step. - * - * Note (March 2004) some editing functions (renaming, commenting) - * are moved to a separate page, edit_document.php. This is also - * where xml and other stuff should be added. - * - * 2) Define the directory to display - * - * 3) Read files and directories from the directory defined in part 2 - * 4) Display all of that on an HTML page - * - * @todo eliminate code duplication between - * document/document.php, scormdocument.php * * @package chamilo.document */ diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index 3256d185d7..ca3296acd1 100755 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -2,6 +2,7 @@ /* For licensing terms, see /license.txt */ use Chamilo\CourseBundle\Entity\CDocument; +use Symfony\Component\HttpFoundation\File\UploadedFile; /** * FILE UPLOAD LIBRARY. @@ -316,7 +317,7 @@ function handle_uploaded_document( $whereToSave = $documentDir.$uploadPath; // At least if the directory doesn't exist, tell so - if (!is_dir($whereToSave)) { + /*if (!is_dir($whereToSave)) { if (!mkdir($whereToSave, api_get_permissions_for_new_directories())) { if ($output) { Display::addFlash( @@ -329,7 +330,7 @@ function handle_uploaded_document( return false; } - } + }*/ // Just upload the file "as is" if ($onlyUploadFile) { @@ -564,8 +565,12 @@ function handle_uploaded_document( $fullPath = $whereToSave.$fileSystemName; $filePath = $uploadPath.$fileSystemName; - if (moveUploadedFile($uploadedFile, $fullPath)) { - chmod($fullPath, $filePermissions); + $request = \Chamilo\CoreBundle\Framework\Container::getRequest(); + $content = $request->files->get('file'); + + //if (moveUploadedFile($uploadedFile, $fullPath)) { + if (true) { + ///chmod($fullPath, $filePermissions); // Put the document data in the database $documentId = add_document( $courseInfo, @@ -577,12 +582,15 @@ function handle_uploaded_document( 0, // read only true, // save visibility $groupId, - $sessionId + $sessionId, + 0, + true, + $content ); if ($documentId) { // Update document item_property - api_item_property_update( + /*api_item_property_update( $courseInfo, TOOL_DOCUMENT, $documentId, @@ -593,14 +601,14 @@ function handle_uploaded_document( null, null, $sessionId - ); + );*/ // Redo visibility - api_set_default_visibility($documentId, TOOL_DOCUMENT, null, $courseInfo); + //api_set_default_visibility($documentId, TOOL_DOCUMENT, null, $courseInfo); } // If the file is in a folder, we need to update all parent folders - item_property_update_on_folder($courseInfo, $uploadPath, $userId); + //item_property_update_on_folder($courseInfo, $uploadPath, $userId); // Display success message to user if ($output) { @@ -616,7 +624,7 @@ function handle_uploaded_document( return $filePath; } else { - if ($output) { + /*if ($output) { Display::addFlash( Display::return_message( get_lang('UplUnableToSaveFile'), @@ -626,7 +634,7 @@ function handle_uploaded_document( ); } - return false; + return false;*/ } break; case 'nothing': @@ -653,8 +661,9 @@ function handle_uploaded_document( ); } } else { + if (moveUploadedFile($uploadedFile, $fullPath)) { - chmod($fullPath, $filePermissions); + //chmod($fullPath, $filePermissions); // Put the document data in the database $documentId = add_document( @@ -1384,12 +1393,14 @@ function add_document( $media->setProviderName($provider); $media->setEnabled(true); - - $handle = tmpfile(); - fwrite($handle, $content); - $file = new \Sonata\MediaBundle\Extra\ApiMediaFile($handle); - $file->setMimetype($media->getContentType()); - + if ($content instanceof UploadedFile) { + $file = $content; + } else { + $handle = tmpfile(); + fwrite($handle, $content); + $file = new \Sonata\MediaBundle\Extra\ApiMediaFile($handle); + $file->setMimetype($media->getContentType()); + } $media->setBinaryContent($file); diff --git a/public/courses.php b/public/courses.php index c5def9eb77..d315caef47 100644 --- a/public/courses.php +++ b/public/courses.php @@ -11,7 +11,7 @@ $publicPath = api_get_path(WEB_PUBLIC_PATH); // http://localhost/chamilo2/courses/ABC/document/aa.html $courseCode = Security::remove_XSS($_GET['courseCode']); $path = Security::remove_XSS($_GET['url']); -$type = Security::remove_XSS($_GET['type']) ?? 'show'; +$type = Security::remove_XSS($_GET['type'] ?? 'show') ; $url = $publicPath."courses/$courseCode/document/$path?type=$type"; header("Location: $url"); exit;