Project

General

Profile

Bug #563

Path problem when uploading media (except images) with fckeditor + fix

Added by Hubert Borderiou almost 10 years ago. Updated over 7 years ago.

Status:
Bug resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
Start date:
01/02/2010
Due date:
% Done:

0%

Estimated time:
Complexity:
Normal
SCRUM pts - complexity:
?

Description

Hi,

I had a problem uploading files with fckeditor (not the advanced one).
It works fine with images, but not for the other media files.

I have this problem because the name of my dokeos folder on the disk is different than the path used in my URL.
On the filesystem, files are in folder :
/home/dokeos/www/*dokeos*1861
and URL is
http://opus.grenet.fr/dokeos/*dsigu*1861
(I guess this can occured in an installation of another customer)

To save uploaded files on the disk, file \main\inc\lib\fckeditor\filemanager\connectors\php\config.php, use api_get_path(REL_COURSE_PATH) and it doesn't work with my configuration because

REL_COURSE_PATH use REL_PATH that use url_append which is '/dokeos/dsigu1861', and I haven't got any folder dsigu1861 on my disk, the folder is dokeos1861, so it cannot ulpload files.

To correct this, I've edited file main\inc\lib\fckeditor\editor\filemanager\connectors\php\config.php (above line 48), here are my corrections :
(I've commented original lines)

// Path to user files relative to the document root.
//$Config['UserFilesPath']
if (api_is_in_course()) {
 if (!api_is_in_group()) {
  // 1. We are inside a course and not in a group.
  if (api_is_allowed_to_edit()) {
  //   $Config['UserFilesPath'] = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/'; 
   $Config['UserFilesPath'] = '/'.$_configuration['course_folder'].api_get_course_path().'/document/'; 
  } else {
   // 1.2. Student
  //   $Config['UserFilesPath'] = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/shared_folder/sf_user_'.api_get_user_id().'/'; 
   $Config['UserFilesPath'] = '/'.$_configuration['course_folder'].api_get_course_path().'/document/shared_folder/sf_user_'.api_get_user_id().'/';
  }
 } else {
  // 2. Inside a course and inside a group.
  global $group_properties;
  //  $Config['UserFilesPath'] = api_get_path(REL_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/';
  $Config['UserFilesPath'] = '/'.$_configuration['course_folder'].api_get_course_path().'/document'.$group_properties['directory'].'/';
 }
} else {
 if (api_is_platform_admin() && $_SESSION['this_section'] == 'platform_admin') {
  // 3. Platform administration activities.
  //  $Config['UserFilesPath'] = api_get_path(REL_PATH).'home/default_platform_document/';
  $Config['UserFilesPath'] = '/home/default_platform_document/';
 } else {
  // 4. The user is outside courses.
  //  $Config['UserFilesPath'] = api_get_path(REL_PATH).'main/upload/users/'.api_get_user_id().'/my_files/';
  $Config['UserFilesPath'] = '/main/upload/users/'.api_get_user_id().'/my_files/';
 }
}

Now files are nicely uploaded on the server, but I cannot see them in the Dokeos document folder on the Dokeos interface.

I had to modifed data saved on the database (because strlen("dokeos1861") != strlen("dsigu1861"))
Here are my corrections :

File \main\inc\lib\fckeditor\editor\filemanager\connectors\php\commands.php (line 309)

 if ( file_exists( $sFilePath ) ) {
  // $file_path = substr($sFilePath, strpos($sFilePath, $repository_path) + strlen($repository_path) - 1);
 $file_path=preg_replace("/^.*".TOOL_DOCUMENT."/", "", $sFilePath);    

File \main\inc\lib\fckeditor\editor\filemanager\connectors\php\io.php (line 154)

   $folder_path=preg_replace("/^.*".TOOL_DOCUMENT."/", "", $folderPath);    
   $folder_path=preg_replace("/\/$/", "", $folder_path);    // ! remove the last / if any. Should be done in 1 regexp I guess ...
   // $folder_path = substr($folderPath, strpos($folderPath, $repository_path) + strlen($repository_path) - 1);*

It works fine.

Hope this help.

Hubert


Files

config.php (11.6 KB) config.php Hubert Borderiou, 10/02/2010 16:39
tools.tgz (17.7 KB) tools.tgz Tools archive Hubert Borderiou, 20/04/2010 14:52
green_arrow.mp4 (4.3 MB) green_arrow.mp4 How the tool works.mp4 Hubert Borderiou, 20/04/2010 14:52
green_arrow_controller.swf (399 KB) green_arrow_controller.swf swf to use with mp4 (if needed) Hubert Borderiou, 20/04/2010 14:52

History

#1

Updated by Ivan Tcholakov almost 10 years ago

Hello Hubert,

It seems to me that I am the author of the code you are making corrections on. Before getting deep in your proposition I would like to say some initial words.

We are working on Chamilo 1.8.7, you are talking about Dokeos 1.8.6.1? I would like to inform you that since Chamilo 1.8.6.2 the function api_get_path() has some corrections. See (run) the test http://YOUR_HOST/chamilo/tests/main_api.lib.test_standalone.php . Could you check the behaviour you desired about the online editor on Chamilo 1.8.6.2?

I would like to say that corrections on places like this should be made in very conservative manner. This is a difficult work - you may fix something but at the same time you may damage something else without noticing it. In my opinion possible corrections under this task should end with a formal test (with positive result) within some of the created test-suites.

Regards,
Ivan Tcholakov

#2

Updated by Ivan Tcholakov almost 10 years ago

Well, I had a closer look at the proposed code. I think these changes should not be implemented. This task should be rejected.

Ivan.

#3

Updated by Hubert Borderiou almost 10 years ago

I have the same problem on Chamilo 1.8.6.2

I'll check my solution on Chamilo 1.8.6.2 and tell you my results.

I have, I think, to learn how you work, you are right to brief me about it :)
I'll use the test page you gave me http://YOUR_HOST/chamilo/tests/main_api.lib.test_standalone.php

You can close the task, moreover, I'll try a solution without preg_replace to avoid utf-8 issues.

Regards
Hubert

#4

Updated by Ivan Tcholakov almost 10 years ago

A good solution avoids direct use of those "magic" global variables (which are a concept from the past). Please, try always to use the API functions.
A second thought: Your case/configuration is rare, I am not convinced that we have to sacrifice our time for "exotic" kinds of configurations. There are other more important or interesting things to be done.

Anyway, tell me about your findings. Please, about this task, don't change code in the repository, it is mature and tested.

:-)
Ivan

#5

Updated by Hubert Borderiou almost 10 years ago

  • Status changed from New to Feature implemented

Don't worry, I'm reporter, and I'll not make any change in the repository, and I don't want to.
I'm not ( yet? ;-) ) enought in touch with your code to do this.

I try to report that I see, and try to give the most informtation about it.

You're right, I can close this task, and thanks for your advices.

#6

Updated by Juan Carlos RaƱa Trabado almost 10 years ago

  • Status changed from Feature implemented to Needs testing

I reopen this task because i do not know if the bug still remain. If the bug is, it comes to finding the best solution, is not always where one might think. Hubert, the bug is still remain? Ivan just trying to be prudent and maintain the best possible code. If the error isn't still there, I appreciate that comment and close it again. Best wishes.

#7

Updated by Hubert Borderiou almost 10 years ago

Hi,
I worked more on this task and I have the same symptoms on Chamilo 1.8.6.2
(and no problem at all with the (new) function main_api.lib.php)

Actually, in file /main/inc/lib/fckeditor/editor/filemanager/connectors/php/config.php, I have the same issue with $Config['FileTypesPath']
I investigate more, and $Config['FileTypesPath'] is used in files io.php/command.php to built the URL of the uploaded file (fct FileUpload) and (if not empty, but it is the case here) $Config['FileTypesAbsolutePath'] is used for the path on the disk for the ressource file.

On the original config.php file, $Config['FileTypesAbsolutePath'] is build using $Config['FileTypesPath'].

On my configuration (URL=http://opus.grenet.fr/dokeos/chamilo1862 and on disk /home/dokeos/www/chamilo-1.8.6.2) $Config['FileTypesPath'] cannot be used for both URL and path on the FS. It cannot work :s

I have to use two variables, one for the URL and one for the FS.
I've tested it on every configurations on my config, and it's ok.
(See attached file config.php modified)

-----------------------------
The second issue, was to store the information concerning the media file on the database.
I had the same problem, and it results with quite mess in my document table.

Same correction for file \main\inc\lib\fckeditor\editor\filemanager\connectors\php\commands.php (line 309)

if ( file_exists( $sFilePath ) ) {
  // $file_path = substr($sFilePath, strpos($sFilePath, $repository_path) + strlen($repository_path) - 1);
 $file_path=preg_replace("/^.*".TOOL_DOCUMENT."/", "", $sFilePath);   

and file \main\inc\lib\fckeditor\editor\filemanager\connectors\php\io.php (line 154)

   $folder_path=preg_replace("/^.*".TOOL_DOCUMENT."/", "", $folderPath);    
   $folder_path=preg_replace("/\/$/", "", $folder_path);    // ! remove the last / if any. Should be done in 1 regexp I guess ...
   // $folder_path = substr($folderPath, strpos($folderPath, $repository_path) + strlen($repository_path) - 1);*

Hope this help,

regards.

#8

Updated by Hubert Borderiou over 9 years ago

I have the same problem with the latest Chamilo on the repository (2010-04-19)
I forgot, on my solution, to modify the
main/inc/lib/main_api.lib.php
Add afetr line 171

define('COURSE_PATH', 'COURSE_PATH');

and on function api_get_path add a entry for COURSE_PATH

function api_get_path($path_type, $path = null) {

    // hub 2010-04-09
    static $paths = array(
        WEB_PATH                 => '',
        SYS_PATH                 => '',
        REL_PATH                 => '',
        WEB_SERVER_ROOT_PATH     => '',
        SYS_SERVER_ROOT_PATH     => '',
        WEB_COURSE_PATH         => '',
        SYS_COURSE_PATH         => '',
        REL_COURSE_PATH         => '',
        REL_CODE_PATH             => '',
        WEB_CODE_PATH             => '',
        SYS_CODE_PATH             => '',
        SYS_LANG_PATH             => 'lang/',
        WEB_IMG_PATH             => 'img/',
        WEB_CSS_PATH             => 'css/',
        SYS_PLUGIN_PATH         => 'plugin/',
        WEB_PLUGIN_PATH         => 'plugin/',
        SYS_ARCHIVE_PATH         => 'archive/',
        WEB_ARCHIVE_PATH         => 'archive/',
        INCLUDE_PATH             => 'inc/',
        LIBRARY_PATH             => 'inc/lib/',
        CONFIGURATION_PATH        => 'inc/conf/',
        WEB_LIBRARY_PATH         => 'inc/lib/',
        WEB_AJAX_PATH            => 'inc/ajax/',
        SYS_TEST_PATH             => 'tests/',    
        COURSE_PATH        => 'courses/'
    );

(I prefer do this instead of using the main/inc/conf/configuration.php and $configuration variable :
$_configuration['course_folder'] = "courses/")

It works fine on my server with these modification on my chamilo1.8.7a

#10

Updated by Hubert Borderiou over 9 years ago

Sorry, I've add the last comment for the wrong issue...
It was for the green arrow problem... I post it in the right form...

#11

Updated by Jorge Gonzalez over 9 years ago

Ivan Tcholakov wrote:

Hello Hubert,

It seems to me that I am the author of the code you are making corrections on. Before getting deep in your proposition I would like to say some initial words.

We are working on Chamilo 1.8.7, you are talking about Dokeos 1.8.6.1? I would like to inform you that since Chamilo 1.8.6.2 the function api_get_path() has some corrections. See (run) the test http://YOUR_HOST/chamilo/tests/main_api.lib.test_standalone.php . Could you check the behaviour you desired about the online editor on Chamilo 1.8.6.2?

I would like to say that corrections on places like this should be made in very conservative manner. This is a difficult work - you may fix something but at the same time you may damage something else without noticing it. In my opinion possible corrections under this task should end with a formal test (with positive result) within some of the created test-suites.

Regards,
Ivan Tcholakov

I just made an upgrade from 1.8.6.2 to 1.8.7 on Debian and the issue when uploading media is still there.

The root of my web is /var/www/

My Chamilo is at /var/www/chamilo/

When I upload media (eg a video clip), Chamilo tries to write to /var/www/chamilo/chamilo/courses/...

"chamilo/" is appended twice to the web root or rather it is appended once to the chamilo root and it shouldn't.

Jorge Gonzalez

#12

Updated by Yannick Warnier over 8 years ago

  • Status changed from Needs testing to Bug resolved

Also available in: Atom PDF