Welcome Guest, Not a member yet? Register   Sign In
simple file uploading function
#1

[eluser]Mowgli[/eluser]
Hello,

I assume this has already been discussed but for some reason my approach won't work. I do apologize if i sound like a newbie but i'm using file manipulation for the first time.
Here's my function:

Code:
function do_upload()
    {
        $config = array(
            'allowed_types' => 'rar|zip|pdf|doc|docx|xls|xlsx|ppt|pptx',
            'upload_path' => $this->gallery_path,
            'max_size' => 10000
        );
        
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $file_data = $this->upload->data();
        
        $d = date('Y-m-d H:i:s');

        $insert = array(
            'filename' => $file_data['file_name'],
            'title' => htmlspecialchars($this->input->post('title')),
            'extension' => $file_data['file_ext'],
            'date' => $d
        );
        $this->db->insert('files', $insert);

    }

This should be fairly simple. Thanks.
#2

[eluser]Aken[/eluser]
You'll need to explain more about what errors your receiving and what the end result should be.
#3

[eluser]Mowgli[/eluser]
Thanks for replying. Well, only the date and id are being inserted into the db and the file isn't moved in the specified directory.
#4

[eluser]Aken[/eluser]
- Is your file input name 'userfile' as it should be?
- Does your <form> tag include the correct enctype?
- What is the content of $this->upload->data()?
- Does $this->upload->display_errors() show anything?

Not too hard to debug this sort of thing, so go for it.
#5

[eluser]Mowgli[/eluser]
Ok, i did some debugging and i realized i was passing the config variables while loading the library so i had to add a new line of code, for initializing.

$this->load->library('upload', $config);
$this->upload->initialize($config); //new line

All .doc files i tested seem to work fine. On the other hand though PDFs won't work at all and i don't get any error which is weird. Same goes for huge size .rar files (i disabled max_size). Small ones work just fine. Maybe there's a problem with the mimes ?
#6

[eluser]Aken[/eluser]
Adding the initialize line is redundant, and not where your problem was.

The max_size config item is for the upload library only - there may be other limitations for max file uploads within php.ini, your server config (Apache / Windows / whatever), etc.

The PDF problem could be a mime issue. Hard to debug that sort of thing without actual errors, if any.
#7

[eluser]Mowgli[/eluser]
I think there's a limit in php.ini, you're most likely right.
The PDFs i tested back then were about 4-5 MB in size so when i went for a smaller file it worked.
That being said i think the problem is finally solved. Thanks for your help Smile




Theme © iAndrew 2016 - Forum software by © MyBB