feat: add fix_font_path.php utility script
This commit is contained in:
parent
d750ff8c23
commit
2aa671353b
60
fix_font_path.php
Normal file
60
fix_font_path.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?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";
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
x
Reference in New Issue
Block a user