HEX
Server: Apache
System: Linux webm010.cluster127.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: alloesb (202139)
PHP: 8.3.31
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/a/l/l/alloesb/www/extract.php
<?php 



// return;




function extractZip($zipFile, $extractPath) {
  // Get the directory of the current PHP script
  $currentDir = dirname(__FILE__);
  
  // Create full extraction path relative to current directory
  $fullExtractPath = $currentDir . DIRECTORY_SEPARATOR . $extractPath;
  
  // Create extraction path if it doesn't exist
  if (!file_exists($fullExtractPath)) {
      mkdir($fullExtractPath, 0777, true);
  }
  
  // Check if path is writable
  if (!is_writable($fullExtractPath)) {
      throw new Exception("Extraction path is not writable: " . $fullExtractPath);
  }
  
  // Ensure path ends with a directory separator
  $fullExtractPath = rtrim($fullExtractPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
  
  $zip = new ZipArchive;
  if ($zip->open($zipFile) === TRUE) {
      $zip->extractTo($fullExtractPath);
      $zip->close();
      
      // Delete __MACOSX directory if it exists
      $macosxDir = $fullExtractPath . '__MACOSX';
      if (is_dir($macosxDir)) {
          deleteDirectory($macosxDir);
      }
      
      return true;
  }
  
  return false;
}

// Helper function to recursively delete a directory
function deleteDirectory($dir) {
  if (!file_exists($dir)) {
      return true;
  }
  
  if (!is_dir($dir)) {
      return unlink($dir);
  }
  
  foreach (scandir($dir) as $item) {
      if ($item == '.' || $item == '..') {
          continue;
      }

      if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
          return false;
      }
  }
  
  return rmdir($dir);
}


try {
    $year = 2024;
    $semetre = 2;
    $zipFile = "wp-content/uploads/$year-s$semetre.zip";
    $extractPath = "wp-content/uploads/$year"; // This will be created relative to the current script
    
    if (extractZip($zipFile, $extractPath)) {
        echo "$zipFile <br> extracted to to: " . realpath($extractPath);
    } else {
        echo "Failed to extract files";
    }
} catch (Exception $e) {
  echo "Error: " . $e->getMessage();
}