i have pdf file in directory and one php display all file, i want to banned access direct url , the way to achive just click on my php display all file
To restrict direct access to the PDF files and only allow access through your PHP script that displays the files, you can use the following approach:
Move PDF files outside the web root:
Place your PDF files outside the public web directory. For example, if your web root is /var/www/html, move your PDF files to /var/www/pdf_files or another directory that is not accessible via a direct URL.
Update your PHP script:
Modify your PHP script to handle the file display and generate links dynamically. Use a script like the one below:
<?php
$pdfDirectory = '/path/to/pdf_files/';
// Get the list of PDF files
$pdfFiles = glob($pdfDirectory . '*.pdf');
// Display links to the PDF files
foreach ($pdfFiles as $pdfFile) {
$filename = basename($pdfFile);
echo '<a href="view_pdf.php?file=' . urlencode($filename) . '">' . $filename . '</a><br>';
}
?>
In this script, view_pdf.php is a new script that you will create to handle the actual display of PDF files.
Create a new script for handling PDF display (view_pdf.php):
Create a new PHP script (view_pdf.php) to handle the display of PDF files. This script will be responsible for serving the PDF content.
php
Copy code
<?php
$pdfDirectory = '/path/to/pdf_files/';
// Get the requested file from the query parameter
$requestedFile = isset($_GET['file']) ? $_GET['file'] : '';
// Validate the file name to prevent directory traversal
if (preg_match('/^[a-zA-Z0-9_-]+\.pdf$/', $requestedFile) && file_exists($pdfDirectory . $requestedFile)) {
// Set appropriate headers for PDF content
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $requestedFile . '"');
// Output the PDF file content
readfile($pdfDirectory . $requestedFile);
} else {
// Invalid or non-existent file requested
echo 'Invalid request.';
}
?>
This script checks if the requested file is a valid PDF file in the specified directory and then serves the content. Adjust the paths and file validation as needed.
With this setup, users will only be able to access the PDF files through your PHP script, preventing direct access to the files via URLs. Additionally, make sure to implement proper security measures, such as input validation and sanitization, to prevent any security vulnerabilities.
เวอไนน์ไอคอร์ส
ประหยัดเวลากว่า 100 เท่า!
เวอไนน์เว็บไซต์⚡️
สร้างเว็บไซต์ ดูแลเว็บไซต์
Categories
- ai (1)
- cat (1)
- computer internet (285)
- food (2)
- med (23)
- Music Movie (31)
- tool (43)
- ฮวงจุ้ย (9)
- Travel (69)
- Uncategorized (1,439)
- web (628)
- ปุ่มคัดลอก และ ปุ่มลบ มีปัญหา มันจะไปคัดลอกและลบไม่ตรงแถว (โปรแกรมกรีดยางพารา)
- คอลั่ม paid ไม่อ่านค่าใน local storage
- ทำไม เมื่อปิด browser brave แล้วเปิดใหม่ ข้อมูลใน Local storage หาย ครับ
- เพิ่มคอมม่า v69=comma+preview.html
- ใส่ comma ในตัวเลข
- สรุปฟังก์ชันและประโยชน์พิเศษของโปรแกรมตารางบันทึกข้อมูลลูกค้า
- code v66 vs v66-1 ต่างกันอย่างไร
- ข้อมูล Local storage หายไปเอง
- แก้codeต้องแก้ database ให้ตรงกัน
- hover ในช่อง input ทำให้ input ลอยตัว
- โปรแกรมที่เก็บข้อมูลแบบ local storage มีความปลอดภัยแค่ไหน?
- ฟังก์ชั่น ยืดขยายช่อง Threshold (ขีดจำกัด) ในการขยายตัวนั้นสูงเกินไป
- เมื่อให้ gemini บันทึก จดจำไว้ เมื่อต้องการคุยต่อ เข้ามาแชทนี้ หรือ เปิดแชทไหม ต้องอ้างอิงอย่างไร คุณจึงจำได้ ต่อเนื่อง?
- โปรแกรมของเราใช้ html ไฟล์เดียว ถ้าเราเปลี่ยนนามสกุล เป็น .php การทำงานจะต่างกันไหม? มีประโยชน์ในแง่ไหน ความปลอดภัยเป็นยังไง
- เมื่อคุณเปิดลิงก์ใด ๆ ผ่านแอปพลิเคชันอย่าง LINE, Facebook Messenger, หรือแอปโซเชียลมีเดียอื่น ๆ
- การแปลง font .ttf เป็น .js
- โปรแกรมบันทึกข้อมูล
- Protected: ใส่รหัสก่อนส่งฟอร์มเมล (ไม่ต้องมีฐานข้อมูล)
- port 465 vs 587
- ถ้าถูกแฮกhost รหัสเมล ก็ถูกไปด้วย การทำ stmp เนี่ย