#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,660
    Rep Power
    171

    Message: finfo_open(): Failed to load magic database at ''.


    Hello; I use this web page to upload and resize photos and store the the name and id into the database. It works fine but I get a notice as below! What am I doing wrong? I am using Codeigniter.
    It only happens on-line, when I do it locally I dont get the notice!

    Thanks


    A PHP Error was encountered

    Severity: Warning

    Message: finfo_open(): Failed to load magic database at .

    Filename: libraries/Upload.php

    Line Number: 1035
    Controller:

    PHP Code:
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class 
    Gallery extends CI_Controller
        
    {
        
        protected 
    $current_photos=0;
        public function 
    index()
            {
                
    $data['title'] = "Gallary Page";
                
    $data['upload_data']="";
                
    $data['photos']='';
                
    $data['photos_message'] = "No message";
                
    $this->load->vars($data);
                if(
    $this->input->post('submit'))
                    {
                        if(
    $this->load_photos())
                            {    
                                
    $this->do_upload();
                            }
                    }
                else
                    {
                        
    $this->load_photos();
                    }
                
                
    $this->view_things();
            }
        
        function 
    do_upload()
            {
                
    $config['upload_path'] = 'uploads/';
                
    $this->load->model('add_photo_model');
                
    $data['new_photo'] = $this->add_photo_model->new_photo_name();
                
    $config['file_name']  = $data['new_photo'];
                
    //$config['overwrite']  = TRUE;
                
    $config['allowed_types'] = 'gif|jpg|png';
                
    $config['max_size']    = '1500';
                
    $config['max_width']  = '1024';
                
    $config['max_height']  = '1000';
                
    $this->load->library('upload'$config);
            
                if (!
    $this->upload->do_upload())
                    {
                        
    $data['upload_data'] = $this->upload->display_errors();
                        
    $this->load->vars($data);
                    }
                else
                    {
                        
    $photo['details']= array('upload_data' => $this->upload->data());
                        
    $this->add_photo_model->add($data['new_photo']);
                        
                        
    $data['upload_data'] = "The photo has been uploaded successfully";
                        
    $this->load->vars($data);
                        
    $this->resize($data['new_photo']);
                    }
            }
        
        public function 
    resize($photo)
            {
                
    $config['image_library'] = 'gd2';
                
    $config['source_image'] = 'uploads/'.$photo;
                
    $config['new_image'] = 'uploads/thumb_'.$photo;
                
    $config['maintain_ratio'] = TRUE;
                
    $config['width'] = 140;
                
    $config['height'] = 140;
                
    $this->image_lib->initialize($config);
                
    $this->load->library('image_lib'$config);
                
                if (!
    $this->image_lib->resize())
                    {
                        
    $data['resize_errors'] = $this->image_lib->display_errors();
                    }
                else
                    {
                        
    $this->load_photos();
                    }
            }

        public function 
    load_photos()
            {
                
    $this->load->model('load_photos_model');
                
    $photos $this->load_photos_model->check();
                if(
    $photos)
                    {
                        
    $this->current_photos=$photos['number_of_rows'];
                        foreach(
    $photos['results'] as $val)
                            {
                                
                                    
    $data['photos'][]=$val->photo.",".$val->id;
                            }
                        
    $data['photos_message'] = "There are ".$this->current_photos." photos uploaded so far<br />";
                        
    $this->load->vars($data);
                        if(
    $this->current_photos<150)
                            {
                                return 
    true;
                            }
                        else
                            {
                                
    $data['photos_message'] = "Limit! There are already ".$photos['number_of_rows']." uploaded!";
                                
    $this->load->vars($data);
                            }
                    }
                else
                    {
                        
    $data['photos_message'] = "There are no photos uploaded yet!";
                        
    $this->load->vars($data);
                        return 
    true;
                    }
            }
        
            
        public function 
    delete($photo)
            {
                
    $this->load->model('load_photos_model');
                
    $delete $this->load_photos_model->delete($photo);
                if(
    $delete)
                    {
                        
    unlink('uploads/'.$photo.'.jpg');
                        
    redirect(site_url()."gallery");
                    }
                else
                    {
                        
    redirect(site_url()."gallery");
                    }
            }    
         public function 
    view_things()
            {
                
    $this->load->view('header_view');
                
    $this->load->view('gallery_view');
                
    $this->load->view('footer_view');
            }
    }
    Model
    PHP Code:
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class 
    Load_photos_model extends CI_Model
        
    {
            function 
    check()
                {
                    
    $query $this->db->query("SELECT * FROM photos ORDER BY id DESC");
                    if(
    $query->num_rows()>0)
                        {
                            
    $results $query->result();
                            
    $rows $query->num_rows();
                            
    $results_and_rows = array('results'=>$results'number_of_rows'=>$rows);
                            return 
    $results_and_rows
                        }
                    else
                        {
                            return 
    false;
                        }    
                }
                
            function 
    delete($photo=NULL)
                {
                    
    $query $this->db->get_where('photos', array('id' => $photo));
                    if(
    $query->num_rows()==1)
                        {
                            
    $this->db->delete('photos', array('id' => $photo));
                            return 
    true;
                        }
                    else
                        {
                            return 
    false;
                        }
                }
        }
    Another model
    PHP Code:
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class 
    Add_photo_model extends CI_Model
        
    {
            function 
    new_photo_name()
                {
                    
    $query $this->db->query("SELECT id FROM photos ORDER BY id DESC LIMIT 1");
                    if(
    $query->num_rows()>0)
                        {
                            
    $results $query->result();
                            
    $new_file_name $results[0]->id+1;
                        }    
                    else
                        {
                            
    $new_file_name 1;
                        }    
                    
                    return(
    $new_file_name.".jpg");
                }
            
            public function 
    add($new_photo_name)
                {
                    
    $sql "INSERT INTO photos (photo) VALUE (?) ";
                    
    $this->db->query($sql, array($new_photo_name));
                  }
        }
    libraries/upload.php
    PHP Code:
    if (function_exists('finfo_file'))
            {
                
    $finfo finfo_open(FILEINFO_MIME);
                if (
    is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
                
    {
                    
    $mime = @finfo_file($finfo$file['tmp_name']);
    /*Line 1035*/                finfo_close($finfo); 

                    
    /* According to the comments section of the PHP manual page,
                     * it is possible that this function returns an empty string
                     * for some files (e.g. if they don't exist in the magic MIME database)
                     */
                    
    if (is_string($mime) && preg_match($regexp$mime$matches))
                    {
                        
    $this->file_type $matches[1];
                        return;
                    }
                }
            } 
    Last edited by zxcvbnm; November 6th, 2012 at 07:01 PM.

IMN logo majestic logo threadwatch logo seochat tools logo