fileManage.lib.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. ==============================================================================
  5. * This is the file manage library for Dokeos.
  6. * Include/require it in your code to use its functionality.
  7. *
  8. * @package chamilo.library
  9. ==============================================================================
  10. */
  11. /**
  12. * Update the file or directory path in the document db document table
  13. *
  14. * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  15. * @param - action (string) - action type require : 'delete' or 'update'
  16. * @param - oldPath (string) - old path info stored to change
  17. * @param - newPath (string) - new path info to substitute
  18. * @desc Update the file or directory path in the document db document table
  19. *
  20. */
  21. function update_db_info($action, $oldPath, $newPath="")
  22. {
  23. global $dbTable; // table 'document' // RH: see below
  24. /* DELETE */
  25. if ($action == "delete")
  26. {
  27. /* // RH: metadata, update 2004/08/23
  28. these two lines replaced by new code below:
  29. $query = "DELETE FROM `$dbTable`
  30. WHERE path='".$oldPath."' OR path LIKE '".$oldPath."/%'";
  31. */
  32. $to_delete = "WHERE path LIKE BINARY '".$oldPath."' OR path LIKE BINARY '".$oldPath."/%'";
  33. $query = "DELETE FROM $dbTable " . $to_delete;
  34. $result = Database::query("SELECT id FROM $dbTable " . $to_delete);
  35. if (Database::num_rows($result))
  36. {
  37. require_once(api_get_path(INCLUDE_PATH) . "../metadata/md_funcs.php");
  38. $mdStore = new mdstore(TRUE); // create if needed
  39. $mdType = (substr($dbTable, -13) == 'scormdocument') ?
  40. 'Scorm' : 'Document';
  41. while ($row = Database::fetch_array($result))
  42. {
  43. $eid = $mdType . '.' . $row['id'];
  44. $mdStore->mds_delete($eid);
  45. $mdStore->mds_delete_offspring($eid);
  46. }
  47. }
  48. }
  49. /* UPDATE */
  50. if ($action == "update")
  51. {
  52. //Display::display_normal_message("newPath = $newPath");
  53. if ($newPath[0] == ".") $newPath = substr($newPath,1);
  54. $newPath = str_replace('//','/',$newPath);
  55. //Display::display_normal_message("character 0 = " . $newPath[0] . " 1=" . $newPath[1]);
  56. //Display::display_normal_message("newPath = $newPath");
  57. //older broken version
  58. //$query = "UPDATE `$dbTable`
  59. //SET path = CONCAT('".$newPath."', SUBSTRING(path, LENGTH('".$oldPath."')+1) )
  60. //WHERE path = '".$oldPath."' OR path LIKE '".$oldPath."/%'";
  61. //attempt to update - tested & working for root dir
  62. $query = "UPDATE $dbTable
  63. SET path = CONCAT('".$newPath."', SUBSTRING(path, LENGTH('".$oldPath."')+1) )
  64. WHERE path LIKE BINARY '".$oldPath."' OR path LIKE BINARY '".$oldPath."/%'";
  65. }
  66. //echo $query;
  67. //error_log($query,0);
  68. Database::query($query);
  69. //Display::display_normal_message("query = $query");
  70. }
  71. //------------------------------------------------------------------------------
  72. /**
  73. * Cheks a file or a directory actually exist at this location
  74. *
  75. * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  76. * @param - filePath (string) - path of the presume existing file or dir
  77. * @return - boolean TRUE if the file or the directory exists
  78. * boolean FALSE otherwise.
  79. */
  80. function check_name_exist($filePath)
  81. {
  82. clearstatcache();
  83. $save_dir = getcwd();
  84. if(!is_dir(dirname($filePath)))
  85. {
  86. return false;
  87. }
  88. chdir ( dirname($filePath) );
  89. $fileName = basename ($filePath);
  90. if (file_exists( $fileName ))
  91. {
  92. chdir($save_dir);
  93. return true;
  94. }
  95. else
  96. {
  97. chdir($save_dir);
  98. return false;
  99. }
  100. }
  101. /**
  102. * Delete a file or a directory
  103. *
  104. * @author - Hugues Peeters
  105. * @param - $file (String) - the path of file or directory to delete
  106. * @return - bolean - true if the delete succeed
  107. * bolean - false otherwise.
  108. * @see - delete() uses check_name_exist() and removeDir() functions
  109. */
  110. function my_delete($file)
  111. {
  112. if ( check_name_exist($file) )
  113. {
  114. if ( is_file($file) ) // FILE CASE
  115. {
  116. unlink($file);
  117. return true;
  118. }
  119. elseif ( is_dir($file) ) // DIRECTORY CASE
  120. {
  121. removeDir($file);
  122. return true;
  123. }
  124. }
  125. else
  126. {
  127. return false; // no file or directory to delete
  128. }
  129. }
  130. //------------------------------------------------------------------------------
  131. /**
  132. * removes a directory recursively
  133. *
  134. * @returns true if OK, otherwise false
  135. *
  136. * @author Amary <MasterNES@aol.com> (from Nexen.net)
  137. * @author Olivier Brouckaert <oli.brouckaert@skynet.be>
  138. *
  139. * @param string $dir directory to remove
  140. */
  141. function removeDir($dir)
  142. {
  143. if(!@$opendir = opendir($dir))
  144. {
  145. return false;
  146. }
  147. while($readdir = readdir($opendir))
  148. {
  149. if($readdir != '..' && $readdir != '.')
  150. {
  151. if(is_file($dir.'/'.$readdir))
  152. {
  153. if(!@unlink($dir.'/'.$readdir))
  154. {
  155. return false;
  156. }
  157. }
  158. elseif(is_dir($dir.'/'.$readdir))
  159. {
  160. if(!removeDir($dir.'/'.$readdir))
  161. {
  162. return false;
  163. }
  164. }
  165. }
  166. }
  167. closedir($opendir);
  168. if(!@rmdir($dir))
  169. {
  170. return false;
  171. }
  172. return true;
  173. }
  174. //------------------------------------------------------------------------------
  175. /**
  176. * Rename a file or a directory
  177. *
  178. * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  179. * @param - $filePath (string) - complete path of the file or the directory
  180. * @param - $newFileName (string) - new name for the file or the directory
  181. * @return - boolean - true if succeed
  182. * - boolean - false otherwise
  183. * @see - rename() uses the check_name_exist() and php2phps() functions
  184. */
  185. function my_rename($filePath, $newFileName)
  186. {
  187. $save_dir = getcwd();
  188. $path = dirname($filePath);
  189. $oldFileName = basename($filePath);
  190. $newFileName = replace_dangerous_char($newFileName);
  191. // If no extension, take the old one
  192. if ((strpos($newFileName, '.') === FALSE)
  193. && ($dotpos = strrpos($oldFileName, '.')))
  194. {
  195. $newFileName .= substr($oldFileName, $dotpos);
  196. }
  197. // Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz'
  198. // This is useful for folder names, where otherwise '.' would be sticky
  199. // Extension PHP is not allowed, change to PHPS
  200. $newFileName = php2phps($newFileName);
  201. if ($newFileName == $oldFileName) return $oldFileName;
  202. if (strtolower($newFileName) != strtolower($oldFileName) && check_name_exist($path."/".$newFileName)) return false;
  203. // On a Windows server, it would be better not to do the above check
  204. // because it succeeds for some new names resembling the old name.
  205. // But on Unix/Linux the check must be done because rename overwrites.
  206. chdir($path);
  207. $res = rename($oldFileName, $newFileName) ? $newFileName : false;
  208. chdir($save_dir);
  209. return $res;
  210. }
  211. //------------------------------------------------------------------------------
  212. /**
  213. * Move a file or a directory to an other area
  214. *
  215. * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  216. * @param - $source (String) - the path of file or directory to move
  217. * @param - $target (String) - the path of the new area
  218. * @return - bolean - true if the move succeed
  219. * bolean - false otherwise.
  220. * @see - move() uses check_name_exist() and copyDirTo() functions
  221. */
  222. function move($source, $target)
  223. {
  224. if ( check_name_exist($source) )
  225. {
  226. $fileName = basename($source);
  227. if ( check_name_exist($target."/".$fileName) )
  228. {
  229. return false;
  230. }
  231. else
  232. { /* File case */
  233. if ( is_file($source) )
  234. {
  235. copy($source , $target."/".$fileName);
  236. unlink($source);
  237. return true;
  238. }
  239. /* Directory case */
  240. elseif (is_dir($source))
  241. {
  242. // check to not copy the directory inside itself
  243. if (ereg("^".$source."/", $target."/"))
  244. {
  245. return false;
  246. }
  247. else
  248. {
  249. copyDirTo($source, $target);
  250. return true;
  251. }
  252. }
  253. }
  254. }
  255. else
  256. {
  257. return false;
  258. }
  259. }
  260. //------------------------------------------------------------------------------
  261. /**
  262. * Move a directory and its content to an other area
  263. *
  264. * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  265. * @param - $origDirPath (String) - the path of the directory to move
  266. * @param - $destination (String) - the path of the new area
  267. * @return - no return !!
  268. */
  269. function copyDirTo($origDirPath, $destination, $move=true)
  270. {
  271. $save_dir=getcwd();
  272. // extract directory name - create it at destination - update destination trail
  273. $dirName = basename($origDirPath);
  274. if(is_dir($dirName)){
  275. mkdir ($destination."/".$dirName, api_get_permissions_for_new_directories());
  276. $destinationTrail = $destination."/".$dirName;
  277. if(is_dir($destination)){
  278. chdir ($origDirPath) ;
  279. $handle = opendir($origDirPath);
  280. while ($element = readdir($handle) )
  281. {
  282. if ( $element == "." || $element == "..")
  283. {
  284. continue; // skip the current and parent directories
  285. }
  286. elseif ( is_file($element) )
  287. {
  288. copy($element, $destinationTrail."/".$element);
  289. if($move)
  290. {
  291. unlink($element) ;
  292. }
  293. }
  294. elseif ( is_dir($element) )
  295. {
  296. $dirToCopy[] = $origDirPath."/".$element;
  297. }
  298. }
  299. closedir($handle) ;
  300. if ( sizeof($dirToCopy) > 0)
  301. {
  302. foreach($dirToCopy as $thisDir)
  303. {
  304. copyDirTo($thisDir, $destinationTrail, $move); // recursivity
  305. }
  306. }
  307. if($move)
  308. {
  309. rmdir ($origDirPath) ;
  310. }
  311. chdir($save_dir);
  312. }
  313. }
  314. }
  315. //------------------------------------------------------------------------------
  316. /* NOTE: These functions batch is used to automatically build HTML forms
  317. * with a list of the directories contained on the course Directory.
  318. *
  319. * From a thechnical point of view, form_dir_lists calls sort_dir wich calls index_dir
  320. */
  321. /**
  322. * Gets all the directories and subdirectories
  323. * contented in a given directory
  324. *
  325. * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  326. * @param - path (string) - directory path of the one to index
  327. * @return - an array containing the path of all the subdirectories
  328. */
  329. function index_dir($path) {
  330. $dirArray = array();
  331. $save_dir = getcwd();
  332. if(is_dir($path)){
  333. chdir($path);
  334. $handle = opendir($path);
  335. // reads directory content end record subdirectoies names in $dir_array
  336. if ($handle !== false) {
  337. while ($element = readdir($handle) ) {
  338. if ( $element == "." || $element == "..") continue; // skip the current and parent directories
  339. if ( is_dir($element) ) $dirArray[] = $path."/".$element;
  340. }
  341. closedir($handle) ;
  342. }
  343. // recursive operation if subdirectories exist
  344. $dirNumber = sizeof($dirArray);
  345. if ( $dirNumber > 0 ) {
  346. for ($i = 0 ; $i < $dirNumber ; $i++ ) {
  347. $subDirArray = index_dir( $dirArray[$i] ) ; // function recursivity
  348. $dirArray = array_merge( (array)$dirArray , (array)$subDirArray ); // data merge
  349. }
  350. }
  351. }
  352. chdir($save_dir) ;
  353. return $dirArray ;
  354. }
  355. /**
  356. * Indexes all the directories and subdirectories
  357. * contented in a given directory, and sort them alphabetically
  358. *
  359. * @author - Hugues Peeters <peeters@ipm.ucl.ac.be>
  360. * @param - path (string) - directory path of the one to index
  361. * @return - an array containing the path of all the subdirectories sorted
  362. * false, if there is no directory
  363. * @see - index_and_sort_dir uses the index_dir() function
  364. */
  365. function index_and_sort_dir($path)
  366. {
  367. $dir_list = index_dir($path);
  368. if ($dir_list)
  369. {
  370. //sort($dir_list);
  371. natsort($dir_list);
  372. return $dir_list;
  373. }
  374. else
  375. {
  376. return false;
  377. }
  378. }
  379. /**
  380. * build an html form listing all directories of a given directory
  381. *
  382. */
  383. function form_dir_list($sourceType, $sourceComponent, $command, $baseWorkDir)
  384. {
  385. $dirList = index_and_sort_dir($baseWorkDir);
  386. $dialogBox .= "<form action=\"".api_get_self()."\" method=\"post\">\n" ;
  387. $dialogBox .= "<input type=\"hidden\" name=\"".$sourceType."\" value=\"".$sourceComponent."\">\n" ;
  388. $dialogBox .= get_lang('Move').' '.$sourceComponent.' '.get_lang('To');
  389. $dialogBox .= "<select name=\"".$command."\">\n" ;
  390. $dialogBox .= "<option value=\"\" style=\"color:#999999\">".get_lang('Root')."\n";
  391. $bwdLen = strlen($baseWorkDir) ; // base directories lenght, used under
  392. /* build html form inputs */
  393. if ($dirList)
  394. {
  395. while (list( , $pathValue) = each($dirList) )
  396. {
  397. $pathValue = substr ( $pathValue , $bwdLen ); // truncate cunfidential informations confidentielles
  398. $dirname = basename ($pathValue); // extract $pathValue directory name du nom
  399. /* compute de the display tab */
  400. $tab = ""; // $tab reinitialisation
  401. $depth = substr_count($pathValue, "/"); // The number of nombre '/' indicates the directory deepness
  402. for ($h=0; $h<$depth; $h++)
  403. {
  404. $tab .= "&nbsp;&nbsp;";
  405. }
  406. $dialogBox .= "<option value=\"$pathValue\">$tab>$dirname\n";
  407. }
  408. }
  409. $dialogBox .= "</select>\n";
  410. $dialogBox .= "<input type=\"submit\" value=\"".get_lang('Ok')."\">";
  411. $dialogBox .= "</form>\n";
  412. return $dialogBox;
  413. }
  414. //------------------------------------------------------------------------------
  415. /**
  416. * to extract the extention of the filename
  417. *
  418. * @returns array
  419. * @param string $filename filename
  420. */
  421. function getextension($filename)
  422. {
  423. $bouts = explode(".", $filename);
  424. return array(array_pop($bouts), implode(".", $bouts));
  425. }
  426. /**
  427. * to compute the size of the directory
  428. *
  429. * @returns integer size
  430. * @param string $path path to size
  431. * @param boolean $recursive if true , include subdir in total
  432. */
  433. function dirsize($root,$recursive=true)
  434. {
  435. $dir=@opendir($root);
  436. $size=0;
  437. while($file=@readdir($dir))
  438. {
  439. if(!in_array($file,array('.','..')))
  440. {
  441. if(is_dir($root.'/'.$file))
  442. {
  443. $size+=$recursive?dirsize($root.'/'.$file):0;
  444. }
  445. else
  446. {
  447. $size+=@filesize($root.'/'.$file);
  448. }
  449. }
  450. }
  451. @closedir($dir);
  452. return $size;
  453. }
  454. /*
  455. ===============================================================
  456. CLASS FileManager
  457. ===============================================================
  458. */
  459. /**
  460. This class contains functions that you can access statically.
  461. FileManager::list_all_directories($path)
  462. FileManager::list_all_files($dir_array)
  463. FileManager::compat_load_file($file_name)
  464. FileManager::set_default_settings($upload_path, $filename, $filetype="file", $glued_table, $default_visibility='v')
  465. @author Roan Embrechts
  466. @version 1.1, July 2004
  467. */
  468. class FileManager
  469. {
  470. /**
  471. ---------------------------------------------------------------
  472. Returns a list of all directories, except the base dir,
  473. of the current course. This function uses recursion.
  474. Convention: the parameter $path does not end with a slash.
  475. @author Roan Embrechts
  476. @version 1.0.1
  477. ---------------------------------------------------------------
  478. */
  479. function list_all_directories($path)
  480. {
  481. $resultArray = array();
  482. if (is_dir($path)) {
  483. $save_dir = getcwd();
  484. chdir($path);
  485. $handle = opendir($path);
  486. while ($element = readdir($handle) )
  487. {
  488. if ( $element == "." || $element == "..") continue; // skip the current and parent directories
  489. if ( is_dir($element) )
  490. {
  491. $dirArray[] = $path."/".$element;
  492. }
  493. }
  494. closedir($handle);
  495. // recursive operation if subdirectories exist
  496. $dirNumber = sizeof($dirArray);
  497. if ( $dirNumber > 0 )
  498. {
  499. for ($i = 0 ; $i < $dirNumber ; $i++ )
  500. {
  501. $subDirArray = FileManager::list_all_directories($dirArray[$i]) ; // function recursivity
  502. if (is_array($dirArray) && is_array($subDirArray)) {
  503. $dirArray = array_merge( $dirArray , $subDirArray ) ; // data merge
  504. }
  505. }
  506. }
  507. $resultArray = $dirArray;
  508. chdir($save_dir) ;
  509. }
  510. return $resultArray ;
  511. }
  512. /**
  513. ===============================================================
  514. This function receives a list of directories.
  515. It returns a list of all files in these directories
  516. @author Roan Embrechts
  517. @version 1.0
  518. ===============================================================
  519. */
  520. function list_all_files($dirArray)
  521. {
  522. $elementArray = array();
  523. if(is_dir($dirArray))
  524. {
  525. $save_dir = getcwd();
  526. foreach ($dirArray as $directory)
  527. {
  528. chdir($directory);
  529. $handle = opendir($directory);
  530. while ($element = readdir($handle) )
  531. {
  532. if ( $element == "." || $element == ".." || $element == '.htaccess') continue; // skip the current and parent directories
  533. if ( ! is_dir($element) )
  534. {
  535. $elementArray[] = $directory."/".$element;
  536. }
  537. }
  538. closedir($handle) ;
  539. chdir("..") ;
  540. chdir($save_dir);
  541. }
  542. }
  543. return $elementArray;
  544. }
  545. /**
  546. Load contents of file $filename into memory
  547. and return them as a string.
  548. Function kept for compatibility with older PHP versions.
  549. Function is binary safe (is needed on Windows)
  550. */
  551. function compat_load_file($file_name)
  552. {
  553. $buffer = '';
  554. if(file_exists($file_name))
  555. {
  556. $fp = fopen($file_name, "rb");
  557. $buffer = fread ($fp, filesize ($file_name));
  558. fclose ($fp);
  559. //api_display_debug_info(htmlentities($buffer));
  560. }
  561. return $buffer;
  562. }
  563. /**
  564. * Adds file/folder to document table in database
  565. * improvement from set_default_settings (see below):
  566. * take all info from function parameters
  567. * no global variables needed
  568. *
  569. * NOTE $glued_table should already have backticks around it
  570. * (get it from the database library, and it is done automatically)
  571. *
  572. * @param path, filename, filetype,
  573. $glued_table, default_visibility
  574. * @action Adds an entry to the document table with the default settings.
  575. * @author Olivier Cauberghe <olivier.cauberghe@ugent.be>
  576. * @author Roan Embrechts
  577. * @version 1.2
  578. */
  579. function set_default_settings($upload_path, $filename, $filetype="file", $glued_table, $default_visibility='v')
  580. {
  581. if (!$default_visibility) $default_visibility="v";
  582. //make sure path is not wrongly formed
  583. if( strlen($upload_path) ) $upload_path = "/$upload_path";
  584. else $upload_path = "";
  585. $endchar=substr($filename,strlen($filename)-1,1);
  586. if($endchar=="\\" || $endchar=="/")
  587. {
  588. $filename=substr($filename,0,strlen($filename)-1);
  589. }
  590. $full_file_name = $upload_path."/".$filename;
  591. //$upload_path = str_replace("//", "/", $upload_path);
  592. $full_file_name = str_replace("//", "/", $full_file_name);
  593. $sql_query = "SELECT count(*) as number_existing FROM $glued_table WHERE path='$full_file_name'";
  594. //api_display_debug_info($sql_query);
  595. $sql_result = Database::query($sql_query);
  596. $result = Database::fetch_array($sql_result);
  597. //determine which query to execute
  598. if( $result["number_existing"] > 0 )
  599. {
  600. //entry exists, update
  601. $query="UPDATE $glued_table SET path='$full_file_name',visibility='$default_visibility', filetype='$filetype' WHERE path='$full_file_name'";
  602. }
  603. else
  604. {
  605. //no entry exists, create new one
  606. $query="INSERT INTO $glued_table (path,visibility,filetype) VALUES('$full_file_name','$default_visibility','$filetype')";
  607. }
  608. Database::query($query);
  609. }
  610. /**
  611. * Like in Java, creates the directory named by this abstract pathname,
  612. * including any necessary but nonexistent parent directories.
  613. *
  614. * @author Hugues Peeters <peeters@ipm.ucl.ac.be>
  615. * @author Christophe Gesche <gesche@ipm.ucl.ac.be>
  616. *
  617. * @param string $path - path to create
  618. * @param string $mode - directory permission (default is '770')
  619. *
  620. * @return boolean TRUE if succeeds FALSE otherwise
  621. */
  622. function mkdirs($path, $mode = '0770')
  623. {
  624. if (file_exists($path))
  625. {
  626. return false;
  627. }
  628. else
  629. {
  630. FileManager :: mkdirs(dirname($path), $mode);
  631. //mkdir($path, $mode);
  632. return true;
  633. }
  634. }
  635. } //end class FileManager
  636. /*
  637. ===============================================================
  638. DEPRECATED FUNCTIONS
  639. ===============================================================
  640. */
  641. /**
  642. * @deprecated 06-FEB-2010. The function mkdir() is able to create directories recursively.
  643. * @link http://php.net/manual/en/function.mkdir.php
  644. *
  645. * to create missing directory in a gived path
  646. *
  647. * @returns a resource identifier or FALSE if the query was not executed correctly.
  648. * @author KilerCris@Mail.com original function from php manual
  649. * @author Christophe Gesch� gesche@ipm.ucl.ac.be Claroline Team
  650. * @since 28-Aug-2001 09:12
  651. * @param sting $path wanted path
  652. * @param boolean $verbose fix if comments must be printed
  653. * @param string $mode fix if chmod is same of parent or default (Note: This misterious parameter is not used).
  654. * @global string $langCreatedIn string to say "create in"
  655. */
  656. function mkpath($path, $verbose = false, $mode = "herit")
  657. {
  658. global $langCreatedIn, $_configuration;
  659. $path = str_replace("/", "\\", $path);
  660. $dirs = explode("\\", $path);
  661. $path = $dirs[0];
  662. if ($verbose)
  663. {
  664. echo "<ul>";
  665. }
  666. for ($i = 1; $i < sizeof($dirs); $i++)
  667. {
  668. $path .= '/'.$dirs[$i];
  669. if (ereg('^'.$path,$_configuration['root_sys']) && strlen($path) < strlen($_configuration['root_sys']))
  670. {
  671. continue;
  672. }
  673. if (!is_dir($path))
  674. {
  675. $ret = mkdir($path, api_get_permissions_for_new_directories());
  676. if ($ret)
  677. {
  678. if($verbose)
  679. {
  680. echo '<li><strong>'.basename($path).'</strong><br />'.$langCreatedIn.'<br /><strong>'.realpath($path.'/..').'</strong></li>';
  681. }
  682. }
  683. else
  684. {
  685. if ($verbose)
  686. {
  687. echo '</ul>error : '.$path.' not created';
  688. }
  689. $ret = false;
  690. break;
  691. }
  692. }
  693. }
  694. if ($verbose)
  695. {
  696. echo '</ul>';
  697. }
  698. return $ret;
  699. }