Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

Access Forbidden To view image file located in Codeigniter view foldr

I have the following structure,

root folder
--- application
    --admin
        --controllers
        --models
        --views
           --newsletter
             --images
             --screenshot.png
             --index.php
--- system
---
---
---

as u can see there is a png file inside application/admin/views/newsletter/

when i am using this img src

application/admin/views/newsletter/screenshot.png" />

i see the image as broken link

but when i paste the address of the image in the addess bar of the browser, it says

"Permission Denied"

how can i make the image be seen, without changing the file structure..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

That's because any direct access to application folder is blocked by Deny from all rule in application/.htaccess file (by default). If you remove that, it would work.

But, it's better to put all public files out of application folder. You could create a folder like public or assets beside index.php file and put all public files inside that.

And if you're using rewrite rules to remove /index.php/ from URLs, consider adding a condition (as the example below) if you don't want them to be treated by RewriteRule:

RewriteCond $1 !^(index.php|robots.txt|favicon.ico|public)
                           # Add your files/folders --^

Then the src would be something like: base_url().'public/newsletter/screenshot.png'.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...