File manager - Edit - /home/missmand/public_html/learning/old/main/couple/doc_system.php
Back
<?php /* For licensing terms, see /license.txt */ /** * Fonctions d'écriture / lecture des fichiers sur le disque * @author Batiste Roger <batiste.roger@live.fr> * @package chamilo.couple */ require_once '../inc/global.inc.php'; require_once(api_get_path(SYS_PATH) . 'main/couple/model.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/tool.php'); require_once(api_get_path(SYS_PATH) . 'main/couple/error.php'); define('DIRECTORY_FOR_UPLOAD', api_get_path(SYS_PATH) . 'main/cooperation/files/'); function doc_get_blacklist() { return array("php", "js", "exe", ""); } function doc_get_maxsize() { return 1 * 1024 * 1024; } function doc_convert_filename ($filename) { $replace="_"; $pattern="/[^a-zA-Z0-9\.]/"; $filename1 = preg_replace($pattern,$replace,$filename); $filename2 = str_replace($replace,'',$filename1); return $filename2; } /** * Upload a file for this couple * @param type $couple_id * @param type $couple_type * @return success boolean */ function doc_upload_file($couple_id, $couple_type) { $file_name = $_FILES["file"]["name"]; $blacklist = doc_get_blacklist(); $extension = end(explode(".", $file_name)); $max_size = doc_get_maxsize(); if (in_array($extension, $blacklist)) error_throw("Le fichier ne peux être téléchargé car son extention ($extension) n'est pas authorisée"); if ($_FILES["file"]["size"] > $max_size) error_throw("Le fichier est trop gros. Taille : " . $_FILES["file"]["size"] . ". Maximum : " . $max_size); $full_path = doc_get_path($couple_id, $couple_type); if (!file_exists($full_path)) mkdir($full_path, 0777, true); // Convert filename to a valid format $valid_file_name = doc_convert_filename($file_name); if (file_exists($full_path . $valid_file_name)) { return error_throw ($valid_file_name . " already exists. "); } else { $success = move_uploaded_file($_FILES["file"]["tmp_name"], $full_path . $valid_file_name); error_test_param($success, 'Error in move_uploaded file'); return true; } } /** * Checks that this file exists * @param type $couple_id * @param type $couple_type * @param type $filename * @return type */ function doc_exists ($couple_id, $couple_type, $filename) { $system_files = doc_system_read($couple_id, strtoupper($couple_type)); if (empty($system_files)) return false; return in_array($filename, $system_files); } /** * Lists all files for this couple * @param type $couple_id * @param type $couple_type * @return null */ function doc_system_read ($couple_id, $couple_type) { try { $full_path = doc_get_path($couple_id, $couple_type); } catch (Exception $e) { return null; } if (!file_exists($full_path)) return null; $dir_list = scandir($full_path); return $dir_list; } function doc_get_path ($couple_id, $couple_type) { if (!couple_id_is_valid($couple_id, $couple_type)) { error_throw('Invalid couple'); } else { $type = strtolower($couple_type); $path_to_couple = "$couple_id/$type/"; return DIRECTORY_FOR_UPLOAD . $path_to_couple; } } /** * * @param type $couple_id * @param type $couple_type * @param type $converted_filename * @return boolean */ function doc_system_delete($couple_id, $couple_type, $converted_filename) { $filename = $converted_filename; // This is to emphasis on the fact that filename has to be converted into filesystem format before if (!doc_exists($couple_id, $couple_type, $filename)) { error_log("doc system delete : !doc_exists($couple_id, $couple_type, $filename)"); return false; } try { $path = doc_get_path($couple_id, $couple_type); } catch (Exception $e) { error_log("doc system delete : doc_get_path($couple_id, $couple_type) => " . $e->getMessage()); return false; } if (is_readable($path . $filename)) { $result = unlink($path . $filename); // error_log("doc system delete : unlinking $path$filename => $result"); return $result; } else { error_log("doc system delete : can't read $path$filename"); return false; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings