Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Deekshith's avatar

prevent php file execution inside users image folder in public

I found one php file inside public folder

Path is like below,

public/userprofilephoto/123123213.php

that code has image validation in laravel where only jpg or png file is allowed now if users trues to access this file directly in browser he will get a access to that file. how to prevent this?

0 likes
4 replies
Deekshith's avatar

I am using below code in public folder htaccess

<FilesMatch "\.php$">
    Order Allow,Deny
    Deny from all
</FilesMatch>
<FilesMatch "index[0-9]?\.php$">
    Order Allow,Deny
    Allow from all
</FilesMatch>
1 like
Deekshith's avatar

accessing public image file directly in browser can able to view.

sr57's avatar

normal that a user can view his files.

view is not execute.

Please or to participate in this conversation.