Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- echo('php user: ' . exec('whoami'));
- include('../config/srvConfig.php');
- if (isset($_SESSION['loggedin']) && isset($_POST['update']) && isset($_FILES['file'])) {
- // Get user information from POST
- $user_id = $_POST['user_id'];
- $username = $_POST['username'];
- $hostname = $_POST['hostname'];
- $title = $_POST['title'];
- $content = $_POST['content'];
- $dir = $_POST['dir'];
- $scrot = $_POST['scrot'];
- // Handle file upload
- $uploadDir = '/var/www/html/uploads/' . $dir . '/';
- $fileName = basename($_FILES['file']['name']);
- $uploadFile = $uploadDir . $fileName;
- // Create the upload directory if it does not exist
- if (!is_dir($uploadDir)) {
- if (!mkdir($uploadDir, 0777, true)) {
- echo 'Failed to create upload directory: ' . $uploadDir;
- exit();
- }
- }
- // Attempt to move the uploaded file
- if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
- // Assuming $conn is your database connection object
- $sql = 'INSERT INTO files (filename, user_id, username, date, dir, notes, scrotpath) VALUES (?, ?, ?, NOW(), ?, ?, ?)';
- if ($stmt = $conn->prepare($sql)) {
- $stmt->bind_param('sissss', $fileName, $user_id, $username, $dir, $content, $scrot);
- $stmt->execute();
- $stmt->close();
- echo 'File uploaded and information saved successfully.';
- } else {
- echo 'Failed to save file information in the database.';
- }
- } else {
- echo 'Failed to upload file. Error: ' . $_FILES['file']['error'];
- }
- } else {
- echo 'You must be logged in and have permission to upload files.';
- }
- // Close the connection
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement