Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7629887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:57:27+00:00 2026-05-31T05:57:27+00:00

I have a problem in CodeIgniter, and that is that when an image is

  • 0

I have a problem in CodeIgniter, and that is that when an image is not found on the server, the instance of a controller is created (besides the one that called the view).

I know all this can sound confusing, so this is the code to observe what I’m saying. I did this changes to a clean 2.1.0 CI version:

Add a controller to override the 404 error page, I added this one:

// add application/controllers/Errors.php 
Class Errors extends CI_Controller {

    public function error_404() {
        echo 'error';
    }
}
// change routes.php
$route['404_override'] = 'Errors/error_404';

Use a controller that isn’t the default one with an unexisting image, I used this:

// add application/controllers/Foo.php 
Class Foo extends CI_Controller {

    public function index() {
        echo '<img src="doesntexist.png" />';
    }

}

I couldn’t figure out another way of debugging it, so I created a log to write the events on CodeIgniter.php:

// add on CodeIgniter.php line 356
$path = 'log.txt'; //Place log where you can find it
$file = fopen($path, 'a');
fwrite($file, "Calling method {$class}/{$method} with request {$_SERVER['REQUEST_URI']}\r\n");
fclose($file);

With this, the log that generates visiting the index function is the following:

Calling method Foo/index with request /test/index.php/Foo
Calling method Errors/error_404 with request /test/index.php/doesntexist.png

Which is the problem I have, an instance of the Error class is created.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:57:28+00:00Added an answer on May 31, 2026 at 5:57 am
    that is that when an image is not found on the server, the instance of a controller is created 
    

    Not really. What I believe is happening is that, since you’re using a relative path for the image (and calling it directly inside a controller, which is wrong because you’re ouputting something before headers), your browser attach the image directly to the CI url, thus making this request to the server:

    index.php/doesntexist.png
    

    Which is (correctly) interpreted by CI as a request to a controller, which doesn’t exists, and therefore it issues the error class.

    You could do, in your actual code (I’d put the images in a view, though):

    echo '<img src="/doesntexist.png" />'
    

    using an absoluth path, or using the base_url() method from the url helper:

    echo '<img src="'.base_url().'doesntexist.png" />
    

    This should tell the server to fetch the right request (/test/doesntexist.png) and won’t trigger that error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CodeIgniter app that works on one server (IIS 6) just fine.
I have a site using CodeIgniter that is almost complete now. My problem is
Fellow coders, i have a function in a codeigniter controller that accepts a couple
I have a problem with CodeIgniter .htaccess file and hope that somebody can help
I am using codeigniter 2 in my project and I have a problem that
I have problem in some JavaScript that I am writing where the Switch statement
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run
I have created a helper that requires some parameters and should upload a file,
I have a strange problem with codeigniter upload class. I use uploadify (http://www.uploadify.com) to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.