CodeIgniter Forums
how cat get the file extension? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how cat get the file extension? (/showthread.php?tid=25293)



how cat get the file extension? - El Forum - 12-07-2009

[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;
        }



how cat get the file extension? - El Forum - 12-07-2009

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

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


how cat get the file extension? - El Forum - 12-07-2009

[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-guide/libraries/file_uploading.html

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


how cat get the file extension? - El Forum - 12-07-2009

[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);



how cat get the file extension? - El Forum - 12-07-2009

[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!