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

[eluser]satie[/eluser]
Mime is ok.
Sad
#12

[eluser]meer[/eluser]
its working fine here
i have coppied your code and made some modifications , its completely working here

Code:
<?php
class File_upload extends CI_Controller{
    
public function __construct()
{
        
  parent::__construct();
  $this->load->helper(array('form'=>'url'));  
}    
public function do_upload()
    {
  $this->load->view('form');
  $config['upload_path'] = './uploads/';
                
  $config['allowed_types'] = 'gif|jpg|png|jpeg';
  //$config['allowed_types'] = '*';
  $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' => './uploads/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
                         //$data['main_content'] = '/annunci/upload_foto';
                  // $this->load->view('templates/template', $data);
  }    
}
}
#13

[eluser]satie[/eluser]
No, for me doesn't work.

I resolve creating a function (in /application/library/) that controls extentions AFTER uploading.
and if returns FALSE delete the file.

Code:
// example $nome_immagine = "ciccio.jpg" AND $estensioni = "jpg|gif"
    public function controlla_estensione($nome_immagine, $estensioni)
    {
        $ext = explode("|", $estensioni);
        $ext_file = explode(".", $nome_immagine);
        $real_ext_file = end($ext_file);
        
        if( in_array($real_ext_file, $ext))
        {
            return TRUE;
        }else{
            unlink($_SERVER['DOCUMENT_ROOT'].'/affido/assets/public/images/'.$nome_immagine);
            return FALSE;
        }
    }

Thanks for your interest. I appreciated.
#14

[eluser]Unknown[/eluser]
Have a similar problems. With
Code:
$config['allowed_types'] = 'csv';

always error "The filetype you are attempting to upload is not allowed.", but MIME types is Ok. With CI 2.03 I haven't that problem, but after upgrading to CI 2.10 it have.
#15

[eluser]weboap[/eluser]
http://stackoverflow.com/questions/74954...s-not-allo

i don't advise to modify the core files, extend the library or copy the specific file to your library folder.
#16

[eluser]satie[/eluser]
Ok. I restored the original file Upload.php in ./system/libraries
And the problem persists.
So upload works if I use
Code:
$config['allowed_types'] = '*';

and It doesn't work if i use:
Code:
$config['allowed_types'] = 'gif|jpg|png';

I create a new function in ./applications/libraries because I'm asking and finding everywhere to know why the problem persists if I specify allowed type.

It wasn't my intention to modify core files: I use a framework to have a safe code.

#17

[eluser]satie[/eluser]
I just activated log files on CI.
After uploading images the log file reports:

ERROR - 2012-06-08 11:57:00 --> Severity: Warning --> getimagesize(): open_basedir restriction in effect. File(C:\Windows\Temp\php69EF.tmp) is not within the allowed path(s): (d:\inetpub\vhosts\website.it\httpdocs\) D:\inetpub\vhosts\website.it\httpdocs\annunci\system\libraries\Upload.php 672
ERROR - 2012-06-08 11:57:00 --> Severity: Warning --> getimagesize(C:\Windows\Temp\php69EF.tmp): failed to open stream: Operation not permitted D:\inetpub\vhosts\website.it\httpdocs\annunci\system\libraries\Upload.php 672

Sad
#18

[eluser]satie[/eluser]
The Server Technicians resolved this issues changing open_basedir in php ini

BEfore:
Code:
d:\inetpub\vhosts\mywebsite.it\httpdocs\;

AFTER:
Code:
d:\inetpub\vhosts\mywebsite.it\httpdocs\;C:\windows\temp

But they suggest to avoid to include C:\windows\temp directory in base_dir: this configuration is not secure.
They suggest to configure in system/libraries/Upload.php of CI with different directory to save tmp file. (for example in CI application. This way permits to configure open_basedir with DOCROOT)

But is it possible?
Or this is a Windows configuration?

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB