Welcome Guest, Not a member yet? Register   Sign In
How do i predetermine the file type for the new Uploader lib?
#1

[eluser]megablue[/eluser]
I'm using the $config['file_name'] to overwrite the default filename supplied by the browser. However since v1.7.2 I'm no longer able to overwrite the filename because the new changes in Uploader require us to provide the file extension. How do i get the file extension (securely) before i process the upload with $this->uploader->do_upload('field_name')?

If i'm using a hard coded ext for the file_name overwrites, the allowed ext would be meaningless.

P/S: the new update breaks my code :/
#2

[eluser]mi6crazyheart[/eluser]
Try this piece of code in u'r controller file...
Code:
$path_info = pathinfo($_FILES["userfile"]["name"]);
$fileExtension = $path_info[‘extension’];

More info:
http://php.net/manual/en/function.pathinfo.php
http://www.w3schools.com/php/php_file_upload.asp
http://www.viewsboard.com/index.php/dboa...ead/28/182
#3

[eluser]megablue[/eluser]
thanks... for the suggestion. However i had used another method, I'll just presume an extension for the uploaded file and then determine its file extension by reading the array return by uploader->data() and rename the file accordingly.
#4

[eluser]mi6crazyheart[/eluser]
Hey, sorry to say but even if u'r method works for u without any problem... still i feel it's not a proper way to do the thing due to because of following reason...

[1] As u said: "I’ll just presume an extension for the uploaded file" ... Do u not feel odd on that u'r script is working on a presume data where u've methods to exactly know what that data is.

[2] May b i miss understood but the "uploader->data()" will give u the information after uploading the file to it's destination place. So, really curious to now how u r doing u'r file uploading with renaming the file . Can u show u'r code a bit here.
#5

[eluser]Unknown[/eluser]
[quote author="megablue" date="1280933392"]I'm using the $config['file_name'] to overwrite the default filename supplied by the browser. However since v1.7.2 I'm no longer able to overwrite the filename because the new changes in Uploader require us to provide the file extension. How do i get the file extension (securely) before i process the upload with $this->uploader->do_upload('field_name')?

If i'm using a hard coded ext for the file_name overwrites, the allowed ext would be meaningless.

P/S: the new update breaks my code :/[/quote]
#6

[eluser]megablue[/eluser]
[quote author="mi6crazyheart" date="1281001659"]Hey, sorry to say but even if u'r method works for u without any problem... still i feel it's not a proper way to do the thing due to because of following reason...

[1] As u said: "I’ll just presume an extension for the uploaded file" ... Do u not feel odd on that u'r script is working on a presume data where u've methods to exactly know what that data is.

[2] May b i miss understood but the "uploader->data()" will give u the information after uploading the file to it's destination place. So, really curious to now how u r doing u'r file uploading with renaming the file . Can u show u'r code a bit here.[/quote]

Actually, I'm only handling upload of images. So i can relies on the php native getimagesize() which used in Uploader->set_image_properties() to provide trust-able data of the uploaded file as long as it is an image file.

Code:
function insert_image($field)
{
        $uqid = md5(uniqid() . uniqid(time()) . $field . $this->site->get_site_id());
        $format = '';
        
        if($data = $this->_do_upload($field, $this->_media_path, $uqid))
        {
            if($data['is_image'] == 1)
            {
                if(rename($this->_media_path . '/' . $uqid . '.jpg', $this->_media_path . '/' . $uqid . '.' . $data['image_type']))
                {
                    //standard site data
                    $media_data = array(
                        'site_id'         => $this->site->get_site_id(),
                        'filename'        => $uqid,
                        'format'        => str_replace('.', '', $data['image_type'])
                    );    
                }
                
                $this->db->insert("ci_media", $media_data);        
                $this->generate_thumb_image($this->_media_path . '/' . $uqid .  '.' . $data['image_type']);
            
                if( $data['image_height'] > 600 )
                {
                    $this->image_resize($this->_media_path . '/' . $uqid . '.' . $data['image_type'], 800, 600, false);
                }
                
                return true;
            }
            else
            {
                unlink($this->_media_path . '/' . $uqid . '.jpg');
            }
        }
        
        return false;
}




Theme © iAndrew 2016 - Forum software by © MyBB