ใช้ได้แต่ต้องเข้าให้ถูกวิธี
ถ้าเข้าโดยกดลิ้งไปที่ไฟล์ลิส index.php จาก line จะไม่สามารถเปิดได้
สำหรับลูกค้า ให้ไปที่หน้าเว็บไซต์ ด้านล่างได้ทำ icon ให้กดได้เเล้ว
why this script can not access pdf file on mobile phone?
<?php
if (isset($_GET['file'])) {
$fileName = $_GET['file'];
// $filePath = 'pdf/' . $fileName; // Assuming your PDF files are in a 'pdf' folder
$filePath = '' . $fileName; // เรียกไฟล์ตามที่ index.php glob มา
if (file_exists($filePath) && strpos($_SERVER['HTTP_REFERER'], 'https://www.cymiz.com/cm/aek/index.php') !== false) {
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $fileName . '"');
readfile($filePath);
} else {
echo 'Invalid request or direct access is not allowed.';
}
} else {
echo 'Invalid request.';
}
?>
There are several reasons why this script might not be able to access the PDF file on a mobile phone. Here are some potential issues to check:
- File Path on Mobile:
- Ensure that the file path on the mobile device is correct. Mobile environments may have different file structures or permissions compared to a desktop environment. Make sure that the file path is valid on the mobile device. (เข้าทางลิ้งที่พิมพ์จากไลน์ ไม่ได้)
- File Permissions:
- Check the file permissions for the PDF file. The web server running the PHP script needs the necessary permissions to read the file. Ensure that the file has readable permissions for the web server.
- HTTP_REFERER Check:
- The
$_SERVER['HTTP_REFERER']
check might be causing issues. TheHTTP_REFERER
header is not always reliable and can be missing or easily spoofed. Mobile browsers may not always send this header, or it might be different from what you expect. Consider using an alternative method for access control, such as authentication or tokens.
- The
- Mobile Browser Issues:
- Different mobile browsers might behave differently. Test your script on various mobile browsers to see if the issue persists across all of them. (เทสแล้วเข้าทาง web browser ของมือถือได้)
- Debugging:
- Add some debugging statements to your script to log information about the file path, server headers, and any error messages. This can help you identify where the problem is occurring.
Here’s an example of how you can add debugging statements:
<?php
if (isset($_GET['file'])) {
$fileName = $_GET['file'];
$filePath = '' . $fileName;
// Debugging statements
echo 'File Path: ' . $filePath . '<br>';
echo 'HTTP_REFERER: ' . $_SERVER['HTTP_REFERER'] . '<br>';
if (file_exists($filePath) && strpos($_SERVER['HTTP_REFERER'], 'https://www.cymiz.com/cm/aek/index.php') !== false) {
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $fileName . '"');
readfile($filePath);
} else {
echo 'Invalid request or direct access is not allowed.';
}
} else {
echo 'Invalid request.';
}
?>
(เทสแล้วเหมือนเดิม)
By checking the debug information, you might get more insights into what could be causing the issue.