File Manager
<!DOCTYPE html>
<html>
<head>
<title>Upload Files</title>
</head>
<body>
<?php
// Process file upload if upload form is submitted
if (isset($_POST['upload'])) {
// Get directory path from form
$directory = $_POST['directory'];
// Validate and sanitize directory path
$directory = rtrim($directory, '/'); // Remove trailing slash
$directory = filter_var($directory, FILTER_SANITIZE_STRING);
// Check if directory exists
if (is_dir($directory) && is_writable($directory)) {
// Check if file was uploaded without errors
if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
// Get the uploaded file information
$file_tmp_path = $_FILES['file']['tmp_name'];
$file_name = basename($_FILES['file']['name']);
$file_path = $directory . '/' . $file_name;
// Move the file to the specified directory
if (move_uploaded_file($file_tmp_path, $file_path)) {
echo "File '$file_name' uploaded successfully.";
} else {
echo "Error: Unable to upload the file.";
}
} else {
echo "Error: No file uploaded or there was an upload error.";
}
} else {
echo "Error: Directory '$directory' does not exist or is not writable.";
}
}
?>
<h2>Upload File</h2>
<form method="post" action="" enctype="multipart/form-data">
<label for="directory">Directory Path:</label><br>
<input type="text" id="directory" name="directory" value="/path/to/your/directory/"><br><br>
<label for="file">Choose File:</label><br>
<input type="file" id="file" name="file"><br><br>
<input type="submit" value="Upload" name="upload">
</form>
</body>
</html>
File Manager Version 1.0, Coded By Lucas
Email: hehe@yahoo.com