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');
$response = ['status' => 'error', 'message' => 'Something went wrong'];
if (isset($_FILES['doc_file']) && $_FILES['doc_file']['error'] === 0) {
$uploadDir = realpath(__DIR__ . '/../uploads') . '/';
$outputDir = realpath(__DIR__ . '/../converted') . '/';
if (!is_dir($uploadDir)) mkdir($uploadDir, 0755, true);
if (!is_dir($outputDir)) mkdir($outputDir, 0755, true);
$originalName = uniqid('docx_') . '.docx';
$originalPath = $uploadDir . $originalName;
move_uploaded_file($_FILES['doc_file']['tmp_name'], $originalPath);
$librePath = '/usr/bin/libreoffice'; // adjust path if needed
$cmd = escapeshellcmd("$librePath --headless --convert-to pdf --outdir " . escapeshellarg($outputDir) . " " . escapeshellarg($originalPath));
exec($cmd . " 2>&1", $output, $returnCode);
$convertedFile = $outputDir . pathinfo($originalName, PATHINFO_FILENAME) . '.pdf';
$baseUrl = ($_SERVER['HTTPS'] ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME'], 2);
$downloadUrl = rtrim($baseUrl, '/') . '/converted/' . basename($convertedFile);
if ($returnCode === 0 && file_exists($convertedFile)) {
$response = [
'status' => 'success',
'download_url' => $downloadUrl
];
} else {
$response['message'] = 'Conversion failed';
$response['debug'] = [
'cmd' => $cmd,
'output' => $output,
'code' => $returnCode
];
}
} else {
$response['message'] = 'No valid DOCX file uploaded.';
}
echo json_encode($response);