Welcome Guest, Not a member yet? Register   Sign In
File Upload and allowed type
#1

[eluser]satie[/eluser]
Hello,

I know that there's a problem with the library Upload.php in ./system/libraries/
so I change the code using this guide:
http://ellislab.com/forums/viewthread/204725/

But now CI sends me this error:
Quote:Severity: Warning

Message: getimagesize(): open_basedir restriction in effect. File(C:\Windows\Temp\phpBDD8.tmp) is not within the allowed path(s): (d:\inetpub\vhosts\task.netplanet.it\httpdocs\)

Filename: libraries/Upload.php

Line Number: 609


with this configuration in my controller:
Code:
$config['allowed_types'] = 'gif|jpg|png';


But if I use:
Code:
$config['allowed_types'] = '*';

There is no problem.
I would like to avoid to upload all types.

Thanks

#2

[eluser]meer[/eluser]
What actually you wants to do ?
please mention the prblem
either u have problem with file upload type or some thing else...???
#3

[eluser]satie[/eluser]
I'd like to use this configuration in my controller:

Code:
$config['allowed_types'] = 'gif|jpg|png';

But CI sends me the error.
#4

[eluser]meer[/eluser]
can u provide me the controller code?
#5

[eluser]satie[/eluser]
Code:
<?php
class Annunci extends CI_Controller{
    
    public function __construct(){
        parent::__construct();
          
      
    }

  
    
    public function do_upload()
    {
  $config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/affido/assets/public/images/';
                
  //$config['allowed_types'] = 'gif|jpg|png|jpeg';
  $config['allowed_types'] = '*';
                $config['max_size'] = '0';
  $config['max_width']  = '1024';
  $config['max_height']  = '768';
                
                

  $this->load->library('upload', $config);

  if ( ! $this->upload->do_upload() )
                    
  {
    $data = array('error' => $this->upload->display_errors());
   }
  else
  {
                        $data= $this->upload->data();
                        $nome_immagine = $data['file_name'];
                        
                        $config = array(
                        'source_image' => $data['full_path'],
                        'new_image' => $_SERVER['DOCUMENT_ROOT'].'/affido/assets/public/images/thumbs',
                        'maintain_ration' => true,
                        'width' => 150,
                        'height' => 100
                        );
                        
                        $data = array('error' => '');
              $this->load->library('image_lib', $config);
                 $this->image_lib->resize();
                        
                        // inserisco l'immagine nel db
                        $this->load->model('annunci_model');

                      
                        $dati_img = array(
                                'immagine'=>$nome_immagine,
                                'idannuncio' => 1
                            );
                        $query = $this->annunci_model->immagine_inserisci($dati_img);
                  
  }
                
                 $data['main_content'] = '/annunci/upload_foto';
                 $this->load->view('templates/template', $data);
}    
    
    
    

    
    
}
#6

[eluser]meer[/eluser]
Try this in your controller

$temp=preg_replace("/.*\.([^.]+)$/","\\1", $_FILES['your_image_field']['name']);
$fileType=$_FILES['your_image_field']['type'];
$config['allowed_types'] = $temp.'|'.$fileType;
#7

[eluser]satie[/eluser]
Thanks for your answer.

Your regular expression permits me to upload any kind of file.
I'd like to upload only jpg|gif|

But If I use this config
Code:
$config['allowed_types'] = 'gif|jpg|png|jpeg';


CI shows the error message:
However the name of my file is simple and correct "Ninfee.jpg"

:-( damn it!

Thanks again.
#8

[eluser]meer[/eluser]
i think am not understanding your problem properly

i hope you will find out your solution soon:-)

#9

[eluser]satie[/eluser]
Thanks. My english is not good. Sorry.

The file upload works with this config:

Code:
$config['allowed_types'] = '*';

Doesn't work with:

Code:
$config['allowed_types'] = 'gif|jpg|png';

Sad
#10

[eluser]meer[/eluser]
checkout this config arrays in your mime.php file @codeigniter/application/config/mime.php

Code:
'jpeg' => array('image/jpeg', 'image/pjpeg'),
    'jpg' => array('image/jpeg', 'image/pjpeg'),
    'jpe' => array('image/jpeg', 'image/pjpeg'),
    'png' => array('image/png',  'image/x-png'),

if these are not there ,please add this in your mime.php




Theme © iAndrew 2016 - Forum software by © MyBB