Welcome Guest, Not a member yet? Register   Sign In
failed upload file save image file types
#1

[eluser]kakap[/eluser]
this my source:
controller 'upload'
Code:
function uploadfile(){
        //upload file ke server
        if ($this->input->post('name')){
            this->MDownload->addFile();
            $this->session->set_flashdata('message', 'File berhasil diUpload');
            redirect('admin/download/', 'refresh');
        } else{
            $data['path'] = 'Upload';
            $data['title'] = 'Admin | Upload file';
            
            
            $this->load->vars($data);
            $this->load->view('upload');
        }

model 'mupload'
Code:
function addFile(){
        if ($_FILES){
            $config['upload_path'] = './files/';
            $config['allowed_types'] = 'jpg|xls|png|bmp|gif|doc|rtf|txt|zip|rar|pdf|ppt';
            $config['max_size'] = '20000';
            $config['remove_spaces'] = true;
            $config['overwrite'] = false;
            
            $this->load->library('upload', $config);
            
            if (strlen($_FILES['file']['name'])){
                if (!$this->upload->do_upload('file')){
                    $this->upload->display_errors();
                    exit();
                }
                $file = $this->upload->data();
                
                $data = array(
                'name' => $_POST['name'],
                'date' => $_POST['date'],
                'status' => $_POST['status'],
                'size' => $file['file_size'],
                'file' => 'files/'.$file['file_name']
                );
                
                $this->db->insert('download', $data);
            }
        }
    }

view 'upload'
Code:
<?php
$data = array('class' => 'jNice');
echo form_open_multipart('admin/download/uploadfile', $data);
echo "<fieldset>";

echo "<p><label for='name'>Judul</label>";
$data = array('name' => 'name', 'id' => 'name', 'class' => 'text-long');
echo form_input($data)."</p>";

echo "<p><label for='date'>Tanggal</label>";
$data = array('name' => 'date', 'id' => 'date', 'class' => 'text-medium', 'value' => date("j-M-Y g:i a"));
echo form_input($data)."</p>";

echo "<p><label for='status'>Status</label>";
$option = array('active' => 'active', 'inactive' => 'inactive');
echo form_dropdown('status', $option)."</p>";


echo "<p><label for='file'>File</label>";
$data = array('name' => 'file', 'id' => 'file');
echo form_upload($data)."
<span>ekstensi file: <em>jpg, gif, png, bmp, xls, doc, rtf, txt, zip, rar, pdf, ppt</em></span><br />
<span>Maksimal ukuran file : 20mb</span>
</p>";

echo form_submit('submit', 'Simpan');

echo "</fieldset>";
echo form_close();
?&gt;

when I upload image file such *jpg, *gif, *png it worked, but when I tried to upload another file type such *rar, *doc, *etc.. its failed.

is something I missed???

I use CI 1.7.2

thankyou for Ur appresiation
#2

[eluser]timj[/eluser]
I am having the same trouble with the following file types. Won't handle any but the first three:

$config['allowed_types'] = 'gif|jpg|png|pdf|txt|rtf|doc|docx|xls|ppt|jpeg|bmp|zip';
#3

[eluser]JamesTaylor[/eluser]
did anyone get the bottom of this? i'm currently having the same issue as well.
#4

[eluser]timj[/eluser]
Yes, it is a bug that hasn't been fixed (or documented in the User Guide), but the fix is pretty easy. You have to list your document types BEFORE your graphic types:

'pdf|txt|rtf|doc|docx|xls|ppt|zip|gif|jpg|png|jpeg|bmp'

It's be great if they just added this to the User Guide.
#5

[eluser]JamesTaylor[/eluser]
Thanks timj,

i've got side tracked at the moment but its good to answer for when i get back to it!
#6

[eluser]dwin102003[/eluser]
it does not work for me. how can we fix this problem any suggestions?
#7

[eluser]maria clara[/eluser]
maybe you have to check your mimes.php look at it in your system/application/config/.




Theme © iAndrew 2016 - Forum software by © MyBB