Skip to content

PlusMagi's Blog By Pitt Phunsanit

Plus emotional magic to the knowledge of logic.

  • About’s Pitt
Close Button
PlusMagi's Blog By Pitt Phunsanit Apache HTTP Server,architecture,Backend,PHP,Programming default file รูปด้วย .htaccess

default file รูปด้วย .htaccess

2024-10-092024-10-09| phunsanitphunsanit| 0 Comment | 10:00
Categories:
  • Apache HTTP Server
  • architecture
  • Backend
  • PHP
  • Programming

ทำระบบสมาชิกโดยแต่ละ user จะมีภาพประจำตัว โดยเก็บในรูปแบบ \datas\peoples\id ของ user.jpg แต่บางคน (ส่วนใหญ่) ไม่ส่งภาพมา แต่ในหลาย ๆ หน้าจะมีจุดที่แสดงภาพสมาชิก

มี 2 ทางเลือกคือ

  • ใช้คำสั่ง file_exists ตรวจสอบดูว่ามีไฟล์นี้รึเปล่า ถ้ามีก็เอาภาพไปแสดง ถ้าไม่ก็แสดงภาพเป็นเงาดำ ๆ ให้ดูไป
  • อีกวิธีคือ แสดงภาพเหมือนว่ามีไฟล์นี้จริง ๆ แต่ถ้าหาไฟล์ไม่เจอก็ให้ server ไปดึงไฟล์ดีฟอล์ตมาแสดง โดยใน code ไม่ต้องตรวจสอบอะไรเลย

วิธีการคือ สร้างไฟล์ .htaccess ใน \datas\peoples\ โดยมีเนื้อหาคือ

RewriteEngine on # If requested resource exists as a file or directory go to it
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.*) - [L] # Else rewrite requests for non-existent .jpg to default.jpg
RewriteRule (.jpg$) default.jpg [L] # Else rewrite requests for non-existent resources to 404.html
RewriteRule (.*) ../404.html [L]

เมื่อมีการเรียกใช้ภาพ .jpg มาใน folder \datas\peoples\ ตัว apache จะไปหาก่อนว่าไฟล์นั้นมีหรือเปล่า ถ้าไม่มีก็จะใช้ไฟล์ default.jpg มาแสดงแทน แค่นี้ก็ไม่ต้องตรวจสอบทุกจุดที่แสดงภาพแล้วว่ามีภาพจริง ๆ หรือเปล่า

ถ้าใช้ git อ่านเรื่อง git: ไม่สนไฟล์ในโพลเดอร์นี้ ยกเว้น ด้วย

Tags: .htaccess, Default, Directory, file_exists, Folder, placeholder image, Server Configuration, user profile, Web Development, ระบบ, สาระความรู้

แนะแนวเรื่อง

PREVIOUS Previous post: Architecture Concepts (Strong Typing, Compile-time Safety vs Dynamic Scripting)
NEXT Next post: Asynchronous Programming (async/await, Task, Task, Threading)

Projects

  • Statement Columns Mapping Helper
  • PlusMagi Blocks
  • PlusMagi Site Search
  • PlusMagi Tags Reindex
  • jQuery Plus Repeater

Recent Posts

  • เทียบ Database GUI (DBeaver, DBX, DataGrip, Navicat)
  • ทำความรู้จักกับ dbx (getdbx.com): Database Client ยุคใหม่ที่ออกแบบมาเพื่อ Developer
  • Vorsan: แอปสารพัดประโยชน์ที่คนใช้ Mac ควรมีติดเครื่อง
  • Apple แต่งตั้ง จอห์น เทอร์นัส (John Ternus) ขึ้นเป็น CEO โดยไม่ใช่ โจนี ไอฟ์ (Jony Ive)
  • Microsoft Coreutils for Windows: เมื่อคำสั่ง Linux ยอดฮิตพร้อมใช้งานแบบ Native บน Windows

Archives

Categories

  • .net core (44)
  • Accessibility (5)
  • Accounting (54)
  • Action Genre (1)
  • agriculture (2)
  • applied mathematics (61)
  • Archaeology (1)
  • art (90)
  • Artificial Intelligence (85)
  • Astronomy (3)
  • Automotive (6)
  • Automotive History (4)
  • Bioengineering (5)
  • Botany (1)
  • business (1,161)
    • Business Analysis (484)
    • Finance (42)
    • Real Estate (27)
  • cd (138)
  • chemistry (11)
  • ci (141)
  • Civil Engineering (26)
  • CMS (48)
  • collaboration (120)
  • Comics (1)
  • Command Line Interface (26)
  • Communication (157)
  • Communication Studies (1)
  • Community Governance (1)
  • Community Management (1)
  • compliance (1)
  • Computer Engineering (4)
  • Computer Hardware (63)
  • computer science (2,080)
    • AI (394)
    • Biology (113)
      • Environment (34)
    • Cloud Computing (457)
    • Data Visualization (65)
    • Mathematics (46)
  • construction (1)
  • Consumer Electronics (1)
  • container (63)
  • Content Creation (1)
  • Corporate Governance (3)
  • Corporate Law (1)
  • Cosmology (2)
  • Culture (151)
  • data engineering (5)
  • data management (5)
  • Data Modeling (1)
  • Data Privacy (80)
  • data science (7)
  • Data Transformation (171)
  • Database Management (6)
  • Database Systems (3)
  • Design (333)
    • UX/UI (45)
  • development (1)
  • devops (19)
  • DevOps Engineering (1)
  • Digital Electronics (1)
  • digital marketing (2)
  • digital technology (1)
  • disaster management (1)
  • e-learning (1)
  • Earth Science (1)
  • Ecology (1)
  • Education (4)
  • Electrical Engineering (4)
  • Electronics (4)
  • Electronics Engineering (3)
  • Embedded Systems (1)
  • engineering (1,150)
    • architecture (1,021)
    • Building Engineering (111)
  • Entertainment (1)
  • Entrepreneurship (1)
  • environmental (1)
  • Environmental Science (3)
  • Environmentalism (1)
  • Facility Management (1)
  • Fantasy Literature (1)
  • Film (2)
  • film studies (2)
  • Forensic Science (1)
  • front-end development (2)
  • Frontend Development (3)
  • Geographical Information System (1)
  • Geology (1)
  • Governance (6)
  • Grammar (1)
  • graph theory (1)
  • Hardware (5)
  • Health (159)
    • Safety (127)
  • health and safety (1)
  • health and wellness (1)
  • Health Science (2)
  • Home Appliances (1)
  • Human Resources (1)
  • Human-Computer Interaction (1)
  • Humanities (498)
    • Academia (274)
    • history (113)
    • Linguistics (16)
    • Literature (98)
  • Information Architecture (1)
  • Information Management (1)
  • information retrieval (2)
  • Information Science (14)
  • information security (1)
  • Information Technology (3)
  • Insurance (1)
  • International Relations (1)
  • Internet of Things (2)
  • IT Operations (1)
  • landscape architecture (1)
  • Language Arts (1)
  • Law (302)
  • Law and Regulation (1)
  • Legal (1)
  • Legal Advice (1)
  • legal affairs (1)
  • Legal Compliance (3)
  • Legal Framework (1)
  • legal studies (2)
  • legal_affairs (1)
  • library science (2)
  • Life (1,580)
    • Cartoon (41)
    • D.I.Y (62)
    • Mindset (311)
    • Movies (57)
    • Philosophy (229)
    • Psychology (1,188)
      • Behavioral Science (575)
      • Cognitive Science (501)
    • Sci-Fi (65)
    • Tips and Tricks (32)
    • พุทธ (7)
  • Lifestyle (1)
  • logic (1)
  • logistics (1)
  • Machine Learning (2)
  • management (890)
    • knowledge management (295)
      • Documentation (98)
    • productivity (5)
    • Project Management (16)
    • strategy (4)
  • manufacturing technology (1)
  • Marketing (1)
  • Markup Languages (1)
  • Mechanical Engineering (3)
  • Media (1)
  • media studies (3)
  • medicine (1)
  • military history (2)
  • Military Technology (1)
  • Mystery (1)
  • Mythology (1)
  • Network (388)
    • IOT (24)
    • Nginx (26)
  • network security (1)
  • networking (56)
  • Neuroscience (1)
  • Object-Relational Mapping (1)
  • operating system (18)
  • Operating Systems (582)
    • Linux (208)
    • macOS (142)
      • Homebrew (25)
    • Shell Script (44)
      • Oh My ZSH (5)
    • Windows (99)
      • PowerShell (26)
  • Operations Management (2)
  • physics (3)
  • Plumbing Systems (1)
  • Pop Culture (1)
  • popular culture (1)
  • Process Improvement (1)
  • Process Management (1)
  • Process Modeling (1)
  • Product Design (1)
  • Programming (2,226)
    • .NET (117)
      • .NET Core EF (9)
      • C# (81)
    • API (535)
      • REST (8)
    • Database (700)
      • MariaDB (38)
      • MySql (69)
      • Oracle Database (24)
      • PostgreSQL (15)
      • RDBMS (55)
      • SQL Server (76)
        • T-SQL (26)
    • Programming Languages (368)
      • Java (95)
      • PHP (216)
      • Python (13)
      • Rust (31)
    • Software Architecture (7)
    • Software Engineering (66)
    • System Analyst (SA) (56)
    • Testing (126)
      • Automated Testing (112)
    • Web (1,534)
      • Apache HTTP Server (37)
      • Backend (1,256)
        • Laravel (54)
        • Spring Boot (15)
      • Frontend (309)
        • Angular (11)
        • CSS (67)
        • JavaScript (188)
        • jQuery (57)
        • Tabulator (24)
        • Tailwind CSS (4)
        • Vue.js (6)
      • WordPress (34)
  • Programming Language (5)
  • Property Law (2)
  • Property Management (3)
  • Public Health (2)
  • Public Policy (1)
  • quality assurance (1)
  • Religion (4)
  • risk management (2)
  • Safety and Security (1)
  • Safety Engineering (3)
  • Science (1)
  • Science Fiction (9)
  • SecDevOps (828)
    • automation (298)
    • CI/CD (137)
    • Docker (89)
    • GIT (58)
    • SVN (6)
    • system (232)
      • System Administration (22)
  • Security (493)
    • Authentication (123)
    • Cryptography (43)
    • Cybersecurity (304)
  • Sensory Technology (1)
  • SEO (1)
  • Server Infrastructure (1)
  • social science (4)
  • Sociology (2)
  • Software Design (1)
  • Software Development (6)
  • software development lifecycle (1)
  • Software Development Practices (1)
  • Software Licensing (3)
  • Software Testing (2)
  • Space Exploration (1)
  • Spirituality (2)
  • sports (1)
  • SQL (1)
  • statistics (2)
  • storage (1)
  • Storage Systems (1)
  • Storytelling (1)
  • structural engineering (1)
  • supply chain (1)
  • Supply Chain Management (1)
  • system architecture (2)
  • system design (6)
  • System Modeling (3)
  • Systems Modeling (1)
  • Systems Programming (2)
  • Technical Support (1)
  • technology (5)
  • Technology History (1)
  • transportation (1)
  • UI (3)
  • Uncategorized (671)
  • urban planning (7)
  • user experience (5)
  • User Experience Design (3)
  • User Interface Design (1)
  • UX Design (3)
  • Version Control (3)
  • Virtualization (1)
  • visualization (1)
  • Web Design (2)
  • web development (67)
  • Web Standards (2)
  • web technology (2)
  • wellness (2)
  • กฎหมาย (3)
  • การขนส่ง (1)
  • การพัฒนาอสังหาริมทรัพย์ (1)
  • จราจร (1)
  • นวนิยายสืบสวน (1)
  • ผังเมือง (1)
  • วรรณกรรม (1)
  • สถาปัตยกรรม (1)
  • อสังหาริมทรัพย์ (2)
  • เทคโนโลยี (1)
  • เรื่องเล่า (1)

Sirat WordPress Theme By VWThemes

Scroll Up
Go to mobile version