LittleDemon WebShell


Linux in-mum-web1499.main-hosting.eu 5.14.0-503.40.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 5 06:06:04 EDT 2025 x86_64
Path : /home/u901718425/domains/cdn.urbanpillar.in/public_html/
File Upload :
Command :
Current File : /home/u901718425/domains/cdn.urbanpillar.in/public_html/update.php

<?php
$dsn = 'mysql:host='.getenv('DB_HOST').';dbname='.getenv('DB_DATABASE');
$username = getenv('DB_USERNAME');
$password = getenv('DB_PASSWORD');


try {
    // Create a PDO instance
    $pdo = new PDO($dsn, $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Define the SQL query
    $query = "SELECT * FROM plan";

    // Prepare and execute the query
    $stmt = $pdo->prepare($query);
    $stmt->execute();
    
    // Fetch the results as an associative array
    $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    foreach ($results as $row) {
        $createdDate = new DateTime($row['date']);
        $path = [];
        $path = $row['floor_plan_image'];
        $id = $row['id']; 
   
         
        // Create a directory structure based on the image's creation date
        $year = $createdDate->format('Y');
        $month = $createdDate->format('m');
        $day = $createdDate->format('d');
        $targetDir = 'uploads/' . $year . '/' . $month . '/' . $day . '/';
       
         if (!is_dir($targetDir)) {
            mkdir($targetDir, 0777, true);
        }
        
        if(isset($path) && $path !=""){
                $sourcePath = 'files/' . basename($path);
                $targetPath = $targetDir . basename($path);
                echo "$sourcePath <br> $targetPath <br><br>";
                if(!is_dir($targetPath) && file_exists($targetPath) ){
                    unlink($targetPath);
                }
            if(move_uploaded_file($sourcePath, $targetPath)){
                if( pathinfo($sourcePath, PATHINFO_EXTENSION) != 'webp'){
                  $targetPath = convert_img_to_webp($sourcePath,$targetDir);
                  
                }
                $updateQuery = "UPDATE `plan` SET `floor_plan_image`= ? WHERE id= ?";
                $updateStmt = $pdo->prepare($updateQuery);
                $updateStmt->execute([$targetPath,$id]);
                echo 'Updated record with new path.<br>';
            }else{
                 if (!is_dir($targetPath) && file_exists($sourcePath)) {
                    // Attempt to move the file
                    if (rename($sourcePath, $targetPath)) {
                        $updateQuery = "UPDATE `plan` SET `floor_plan_image`= ? WHERE id= ?";
                        $updateStmt = $pdo->prepare($updateQuery);
                        $updateStmt->execute([$targetPath,$id]);
                        echo 'Updated record with new path.<br>';
                    }
                 }
            }
                
                
            
        }
           
        }
    
} catch (PDOException $e) {
    // Handle any connection or query errors
    echo 'Connection failed: ' . $e->getMessage();
}
?>

LittleDemon - FACEBOOK
[ KELUAR ]