Hướng dẫn file manager php script - tập lệnh php quản lý tập tin
1. Lpanel 2.4fix
2. Manager 1.15
3. Distro Manager
3. Distro Manager
Tác giả: prasathmani / alexantr tuy mang lại tiện ích quản lý tệp nhanh gọn nhưng hãy cẩn trọng với các sự cố bảo mật mà các hacker có thể sẽ khai thác trên trang của bạn. Github: https://github.com/prasathmani/tinyfilemanager Trong bài viết này mình sẽ hướng dẫn các bạn tạo một trang upload và download file đơn giản sử dụng PHP và MySQL. Form:Trong khi để upload file lên server chúng ta cần tạo một HTML form và đồng thời phải chỉ rõ loại content-type được sử dụng khi submit form. php_value upload_max_filesize 10M php_value post_max_size 20M php_value memory_limit 128M0 ngay bên cạnh để duyệt đến file cần upload. Bằng cách sử dụng PHP php_value upload_max_filesize 10M php_value post_max_size 20M php_value memory_limit 128M1 array, chúng ta có thể upload bất kỳ file nào đang có trên thiết bị lên server. Index đầu tiên của PHP php_value upload_max_filesize 10M php_value post_max_size 20M php_value memory_limit 128M1 array là form input và index thứ hai có thể là name, type, size, tmp_name,error, …
Tăng giới hạn kích thước file upload:Theo mặc định thì kích thước tối đa file upload chỉ là 8MB. Do đó để thay đổi hạn chế về kích thước file được upload thì chúng ta chỉnh sửa file PHP.ini hoặc htaccess. Hầu hết các nhà cung cấp host đều cho phép ghi đè file PHP.ini hoặc .htaccess để thay đổi các giá trị mặc định.Một vài cài đặt có thể được cấu hình bằng phương thức php_value upload_max_filesize 10M php_value post_max_size 20M php_value memory_limit 128M8 khi chạy. Tăng giới hạn kích thước file upload bằng PHP.ini:upload_max_filesize = 10M ; post_max_size = 20M ; memory_limit = 128M Tăng giới hạn bằng cách chỉnh sửa file .htaccess:php_value upload_max_filesize 10M php_value post_max_size 20M php_value memory_limit 128M Gần như mọi host đều cho phép sửa file .htaccess, cho đó bạn có thể thêm đoạn code trên vào cuối file .htaccess, sau đó lưu lại. HTML form input:Database connection:mysql_select_db('filemgr',mysql_connect('localhost','root',''))or die(mysql_error()); Thêm một số hạn chế khi upload file:if(isset($_POST['submit'])!=""){ $name=$_FILES['photo']['name']; $size=$_FILES['photo']['size']; $type=$_FILES['photo']['type']; $temp=$_FILES['photo']['tmp_name']; $error = $_FILES['photo']['error']; $date = date('Y-m-d H:i:s'); if ($error > 0) //Check file upload has error { $_SESSION['alert'] = "danger"; $_SESSION['result'] = "Error: " . $error . " Download file bằng PHP:"application/pdf", "txt" => "text/plain", "html" => "text/html", "htm" => "text/html", "exe" => "application/octet-stream", "zip" => "application/zip", "doc" => "application/msword", "xls" => "application/vnd.ms-excel", "ppt" => "application/vnd.ms-powerpoint", "gif" => "image/gif", "png" => "image/png", "jpeg" => "image/jpg", "jpg" => "image/jpg", "php" => "text/plain" ); if ($mime_type == '') { echo $file_extension = pathinfo($file, PATHINFO_EXTENSION); if (array_key_exists($file_extension, $known_mime_types)) { $mime_type = $known_mime_types[$file_extension]; } else { $mime_type = "application/force-download"; } ; } ; @ob_end_clean(); if (ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); header('Content-Type: ' . $mime_type); header('Content-Disposition: attachment; filename="' . $name . '"'); header("Content-Transfer-Encoding: binary"); header('Accept-Ranges: bytes'); header("Cache-control: private"); header('Pragma: private'); header("Expires: Mon, 26 Jul 2017 05:00:00 GMT"); if (isset($_SERVER['HTTP_RANGE'])) { list($a, $range) = explode("=", $_SERVER['HTTP_RANGE'], 2); list($range) = explode(",", $range, 2); list($range, $range_end) = explode("-", $range); $range = intval($range); if (!$range_end) { $range_end = $size - 1; } else { $range_end = intval($range_end); } $new_length = $range_end - $range + 1; header("HTTP/1.1 206 Partial Content"); header("Content-Length: $new_length"); header("Content-Range: bytes $range-$range_end/$size"); } else { $new_length = $size; header("Content-Length: " . $size); } $chunksize = 1 * (1024 * 1024); $bytes_send = 0; if ($file = fopen($file, 'r')) { if (isset($_SERVER['HTTP_RANGE'])) fseek($file, $range); while (!feof($file) && (!connection_aborted()) && ($bytes_send < $new_length)) { $buffer = fread($file, $chunksize); print($buffer); flush(); $bytes_send += strlen($buffer); } fclose($file); } else die('Error - cannot open file.'); die(); } set_time_limit(0); $file_path = 'files/' . $_REQUEST['filename']; output_file($file_path, '' . $_REQUEST['filename'] . '', ''); ?> Lưu ý:Có một lưu ý nhỏ là code được viết bằng PHP sử dụng php_value upload_max_filesize 10M php_value post_max_size 20M php_value memory_limit 128M9 thay vì 0, do đó các bạn nên chỉnh sửa lại cho phù hợp hoặc chỉ mang tính chất tham khảo. Bài viết được lấy từ: Simple File Manager Using Php Mysql. Các bạn có thể xem demo và download tại đây. |