Uname:
Linux server.thebazaar99.com 5.14.0-687.17.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Jun 22 07:21:26 EDT 2026 x86_64
Software:
Apache
PHP version:
8.3.32 [ PHP INFO ] PHP os:
Linux
Server Ip:
163.227.92.254
Your Ip:
216.73.217.24
User:
gutlooks (1003) | Group:
gutlooks (1005)
Safe Mode:
OFF
Disable Function:
exec,passthru,shell_exec,system
<?php
header('Content-Type: application/json');
// Setup response
$response = ['status' => 'error', 'message' => 'Something went wrong'];
// Check if file was uploaded
if (isset($_FILES['pdf_file']) && $_FILES['pdf_file']['error'] === 0) {
// Set directory paths
$uploadDir = __DIR__ . '/../uploads/';
$outputDir = __DIR__ . '/../converted/';
// Ensure directories exist
if (!is_dir($uploadDir)) mkdir($uploadDir, 0755, true);
if (!is_dir($outputDir)) mkdir($outputDir, 0755, true);
// Save uploaded file
$originalName = uniqid('pdf_') . '.pdf';
$originalPath = $uploadDir . $originalName;
move_uploaded_file($_FILES['pdf_file']['tmp_name'], $originalPath);
// LibreOffice path
$librePath = '/usr/bin/libreoffice'; // change if needed
// Execute command
$cmd = escapeshellcmd("$librePath --headless --convert-to docx --outdir " . escapeshellarg($outputDir) . " " . escapeshellarg($originalPath));
exec($cmd . ' 2>&1', $output, $returnCode);
// Expected output file
$convertedFile = $outputDir . pathinfo($originalPath, PATHINFO_FILENAME) . '.docx';
$convertedURL = '../converted/' . basename($convertedFile);
if ($returnCode === 0 && file_exists($convertedFile)) {
$response = [
'status' => 'success',
'download_url' => $convertedURL
];
} else {
$response['message'] = 'Conversion failed';
$response['debug'] = [
'cmd' => $cmd,
'output' => $output,
'code' => $returnCode
];
file_put_contents(__DIR__ . '/../debug.log', "CMD: $cmd\nReturn Code: $returnCode\nOutput:\n" . implode("\n", $output) . "\n\n", FILE_APPEND);
}
} else {
$response['message'] = 'No valid file uploaded.';
}
echo json_encode($response);