38394-vm/fix_font_path.php
2026-02-14 08:52:29 +00:00

61 lines
1.9 KiB
PHP

<?php
// fix_font_path.php
// Run this script on your server to fix the 'amiri.ttf' path issue.
header('Content-Type: text/plain');
$targetFile = __DIR__ . '/includes/fpdf/font/unifont/amiri.mtx.php';
if (!file_exists($targetFile)) {
echo "Error: File not found at $targetFile\n";
echo "Please ensure you uploaded the 'includes' folder correctly.\n";
exit;
}
$content = file_get_contents($targetFile);
if ($content === false) {
echo "Error: Could not read file.\n";
exit;
}
// Check for the bad path
if (strpos($content, '/home/ubuntu/executor/workspace') !== false) {
echo "Found incorrect path in file. Fixing...\n";
// Replace with dynamic path
$newContent = preg_replace(
"/\'[^\']+\/amiri\.ttf\'/",
"dirname(__FILE__) . '/amiri.ttf'",
$content
);
if ($newContent === null || $newContent === $content) {
// Fallback: manual string replacement if regex fails
$newContent = str_replace(
"'/home/ubuntu/executor/workspace/includes/fpdf/font/unifont/amiri.ttf'",
"dirname(__FILE__) . '/amiri.ttf'",
$content
);
}
if (file_put_contents($targetFile, $newContent)) {
echo "SUCCESS: File updated successfully!\n";
echo "Old path removed. New path is dynamic.\n";
echo "Please delete this script and try downloading the PDF again.\n";
} else {
echo "Error: Could not write to file. Check permissions.\n";
}
} else {
echo "File appears to be correct already.\n";
echo "Current content snippet:\n";
echo substr($content, 0, 500) . "\n...\n";
// Check if it's using dirname(__FILE__)
if (strpos($content, 'dirname(__FILE__)') !== false) {
echo "It is using dirname(__FILE__), which is good.\n";
} else {
echo "Warning: It is NOT using dirname(__FILE__). It might be hardcoded to something else?\n";
}
}
?>