Welcome Guest, Not a member yet? Register   Sign In
how cat get the file extension?
#1

[eluser]tnathos[/eluser]
hi, how i can get the file extension before upload the file? i need know for put the correct path..

img_principal is the input type file in the view...

Code:
$config['file_1']['upload_path']     = './uploads/logos/';
            $config['file_1']['allowed_types']  = 'gif|jpg|png';
            $config['file_1']['encrypt_name']     = true;
        
        !!!!!! here !!!! how can? if(['img_principal']['file_ext']=='swf' ){
        
            $config['file_2']['upload_path']     = './uploads/medios/swf';
            $config['file_2']['allowed_types']  = 'swf|fla';
            $config['file_2']['encrypt_name']     = true;
        
        }else{
        
            $config['file_2']['upload_path']     = './uploads/medios/img';
            $config['file_2']['allowed_types']  = 'gif|jpg|png';
            $config['file_2']['encrypt_name']     = true;
        }
#2

[eluser]tnathos[/eluser]
ok problem solved.. if any have the same dude...

$nombre = $_FILES['img_principal']['name'];
$partes = explode(".", $nombre);
$ext = end($partes);
#3

[eluser]mattpointblank[/eluser]
You can't access it before the upload - how would the server know what type of file it was if it wasn't uploaded to it first?!

http://ellislab.com/codeigniter/user-gui...ading.html

Bottom of that page shows you how to access it after the upload.
#4

[eluser]tnathos[/eluser]
thaks.. but i solved the problem whit the code before init the upload... whit this i can know the file extesion and make variable the config path, for multiple uploas files.. xd

Code:
$nombre = $_FILES[‘img_principal’][‘name’];
      $partes = explode(”.”, $nombre);
      $ext = end($partes);
#5

[eluser]WebbHelp[/eluser]
There is a function build in PHP5.

Code:
$nombre = pathinfo($_FILES['img_principal']['name']);
echo $nombre['extension'];

This givs you the file extension, to!




Theme © iAndrew 2016 - Forum software by © MyBB