Welcome Guest, Not a member yet? Register   Sign In
storing images outside of public_html
#11

[eluser]samseko[/eluser]
Hmm, got some ongoing issues related to this:

With the use of the non-standard location for the images and this controller - i am finding it hard to include pagination.

I was trying to integrate the pagination(s) within the main controller for the images i used above.

If integrate the default ci pagination the integer appended to this url prompts me to save it ( integer ) as a file?

Also tried integrating the ajax pagination, which in itself was loading the relevant page links, though no images were showing?
#12

[eluser]TheFuzzy0ne[/eluser]
I'm sorry, but I don't understand the problem. Pagination should have nothing to do with the images, but rather the pages that contain the images. The images themselves should be treated as single images. Can you show an example of what's not working?
#13

[eluser]samseko[/eluser]
When i use the ci pagination library and class, if i click on the pagination links created, it tries to append the link to the image loading part of the controller. That is, i get a download prompt for 'image//backend/members-section/10'

This part is causing it, from what i can tell: 'header('Content-Type: image/'.$file_ext);'

Here's the controller i have now:
Code:
function members_section($image_name="")
    {
        $username = $this->dx_auth->get_username();
        if ($image_name)
        {
            // Some validation here.
            
            // If the requested image belongs to the user requesting it...
            
            // for security reasons, don't allow "../" in the request URI
            
            $server_request = str_replace('../', '', $_SERVER['REQUEST_URI']);
            // Rewrite the request to the path on your server
            $file = '../system/uploads/'.$image_name;
            // Get the requested path and explode it by the dots
            $file_ext = explode('.', $_SERVER['REQUEST_URI']);
            // The last value in the array will be the file extention, pop it off
            $file_ext = array_pop($file_ext);
            // Use the file extention in the MIME type so you don't have to write
            // a switch or if/else for every image type (jpg, gif, png)
            header('Content-Type: image/'.$file_ext);
            readfile($file);
        }
        // load pagination class
        $this->load->library('pagination');
        $config['base_url'] = base_url().'backend/members_section';
        $config['total_rows'] = $this->db->where('username', $username)->count_all('pictures', 'ASC');
        $config['per_page'] = '10';
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
    
        $this->pagination->initialize($config);
        
        $this->load->model('entries_pagination');
        $data['results'] = $this->entries_pagination->get_entries($config['per_page'],$this->uri->segment(3));
        
        // load the view
        $this->load->view('backend/members_section', $data);
    }
#14

[eluser]TheFuzzy0ne[/eluser]
The method used to request an image should be totally separate from pagination or anything else. The controller should simply validate the user, and return the requested image. Nothing else. No views, no pagination, nothing.

Hope this helps.
#15

[eluser]samseko[/eluser]
I must be doing something wrong because I'm getting blank thumbnails again.

Here is the controller code:
Code:
function members_section()
    {
        $username = $this->dx_auth->get_username();
        //$data['query'] = $this->db->where('username', $username)->get('pictures');
        // load pagination class
        $this->load->library('pagination');
        $config['base_url'] = base_url().'backend/members_section';
        $config['total_rows'] = $this->db->where('username', $username)->count_all('pictures', 'ASC');
        $config['per_page'] = '10';
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
    
        $this->pagination->initialize($config);
        
        $this->load->model('entries_pagination');
        $data['results'] = $this->entries_pagination->get_entries($config['per_page'],$this->uri->segment(3));
        
        // load the view
        $this->load->view('backend/members_section', $data);
    }
    function members_image($image_name="")
    {
        if ($image_name)
        {
            // Some validation here.
            
            // If the requested image belongs to the user requesting it...
            
            // for security reasons, don't allow "../" in the request URI
            
            $server_request = str_replace('../', '', $_SERVER['REQUEST_URI']);
            // Rewrite the request to the path on your server
            $file = '../system/uploads/'.$image_name;
            // Get the requested path and explode it by the dots
            $file_ext = explode('.', $_SERVER['REQUEST_URI']);
            // The last value in the array will be the file extention, pop it off
            $file_ext = array_pop($file_ext);
            // Use the file extention in the MIME type so you don't have to write
            // a switch or if/else for every image type (jpg, gif, png)
            header('Content-Type: image/'.$file_ext);
            readfile($file);
        }
    }
And snippet from the view that loads the thumbnail:
Code:
</img src="/backend/members_image/&lt;? echo $row->thumbnail; ?&gt;">

I am assuming that 'src="/backend/members_image/' would poll the relevant controller?
#16

[eluser]TheFuzzy0ne[/eluser]
You assume correctly. Check the HTML source, and ensure that the img src attribute is correctly set. If it is, try using the URL directly in the address bar to confirm it's working. If it's not, you may need to debug each line of your members_image method using log_message(), just to check that each line is producing the right results.
#17

[eluser]samseko[/eluser]
You're a LEGEND.

The problem was URI Permissions. All good now, and the thumbs display!

Sometimes, like in this situation, i should do obvious tests, rather than scratch my head wondering why the code don't work.
#18

[eluser]TheFuzzy0ne[/eluser]
I totally agree. Quite often you can actually do all the tests you need in less time than it takes to scratch your head whilst looking confused. Sadly, I still seem to spend too long doing the latter.

I'm glad you got it sorted. Smile




Theme © iAndrew 2016 - Forum software by © MyBB