the error only occurs on a particular file. a lot of files with the extension XLS and XLSX have been uploaded.
My mimes:
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream','application/msexcel'),
Upload config:
$config['allowed_types'] = '*';
$config['max_size'] = '0';
The Error:
The filetype you are attempting to upload is not allowed.
Try Providing the Upload config specifically
$config['allowed_types'] = 'xls|xlsx';
$config['max_size'] = '0';
Related
I have a problem with the xls and xlsx mimes types. I'm trying to upload an excel file but I get string(130)
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
but i have that type in mi xlsx mime
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'),
This is my upload controller
public function agregararchivo() {
if ($_FILES["userfile"]['name']=='') {
// Here you can directly redirect to the form page itself with the Error Message
} else {
$new_name = time().$_FILES["userfile"]['name']; //This line will be generating random name
$config['upload_path'] = FCPATH ."assets/imagenusuario/";
$config['allowed_types'] = 'xlsx|xls';
$config['file_name'] = $new_name;
$this->load->library('upload', $config); //Loads the Uploader Library
$this->upload->initialize($config);
if (!$this->upload->do_upload('userfile')) {}
else {
$data = $this->upload->data();
}
}
}
I don't know what is wrong, if I have that type in the mimes it should work but it doesn't.
Just had the same problem with mime_content_type()
It's a PHP bug, you can see it here: https://bugs.php.net/bug.php?id=77784
I successfully create multiple file upload. But, for some reason it fails to upload zip type files.
$config['upload_path'] = FCPATH."assets/uploads/";
$path = $config['upload_path'];
$config['allowed_types'] = 'gif|jpg|jpeg|png|bmp|doc|docx|ppt|pptx|xls|xlsx|txt|pdf|sql|html|rar|zip|7z';
$config['max_size'] = '5120';
$this->load->library('upload', $config);
$this->upload->initialize($config);
If I add this $this->upload->set_allowed_types('*');. The zip files are uploaded. But, I don't want to use this. Because it allows all type to be uploaded.
I am working in codeigniter framework.I want to upload doc or docx file.So i have write code like this:
$config['upload_path'] = './uploads/resume/';
$config['allowed_types'] = 'docx|doc|DOC|DOCX';
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('resume'))
{
print_r($error = array('error' => $this->upload->display_errors()));
}
else
{
$upload = $this->upload->data();
print_r($upload);exit;
}
Here, it shows and error like The filetype you are attempting to upload is not allowed. And file is not uploaded.
I have also modify mimes.php file and add
'doc' => array('application/msword', 'application/vnd.ms-office'),
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'),
When I print $this->upload->data() then it shows file_type as application/vnd.oasis.opendocument.text
But, its not working.So how can I upload doc or docx file?
Here I have created doc array in mimes.php like this :
'doc' => array('application/msword', 'application/vnd.ms-office','application/vnd.oasis.opendocument.text')
and its working.
I don't see "application/vnd.oasis.opendocument.text" in your array of allowed mime types.
Don't forget max_size and allowed type to txt
$config['allowed_types'] = 'txt|doc|docx';
$config['max_size'] = 10000;
$this->load->library('upload', $config);
If still fails load OpenOffice extension too
$config['allowed_types'] = 'application/vnd.oasis.opendocument.spreadsheet | application/vnd.oasis.opendocument.text | application/vnd.oasis.opendocument.presentation |
application/vnd.openxmlformats-officedocument.wordprocessingml.document | application/vnd.ms-excel | application/vnd.openxmlformats-officedocument.presentationml.presentation | txt';
Add the following to the mimes.php file
'binary/octet-stream'
for each office document type you want to support. Not an ideal solution but works for me.
I'm setting up an upload form in CodeIgniter. I've setup the allowed_types parameter to:
$config['allowed_types'] = 'xls|xlsx';
And added the following line to config/mimes.php:
'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
However, despite the file I'm trying to upload being an xlsx file CI is still telling me the filetype isn't allowed. Any thoughts?
public function do_upload() {
// Change this if you change the upload directory
$upload_path = "/webusers/ad6vcf/public_html/funding_manager/application/uploads";
$config['upload_path'] = $upload_path;
//At some point will add support for csv
$config['allowed_types'] = 'xls|xlsx';
//Max 5000kb please
$config['max_size'] = '5000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->upload($error);
} else {
$upload_data = $this->upload->data();
bulk_insert($upload_path . $upload_data['file_name']);
}
}
Please try this
$this->load->library('upload', $config);
$this->upload->initialize($config);
Have you tried this?
if (!$this->upload->do_upload('put the name of the input field here'))
I can't upload ogg / ogv file. the error message is
The filetype you are attempting to upload is not allowed.
I have tried this in the mimes.php
'ogg' => array('application/x-ogg', 'application/ogg', 'audio/x-ogg, application/octet-stream'),
'ogv' => array('application/ogv', 'video/ogv')
and in the controller
$config['upload_path'] = 'assets/assets/video/';
$config['allowed_types'] = 'ogv|ogg';
$config['file_name'] = "samsame";
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload('videoname');
$error = $this->upload->display_errors();
You have to initialize the $config array, so your problem will be solved. You are trying to upload without initializing. Please write the below line after loading the library.
$this->upload->initialize($config);
Also check that your form must be multipart
You can also rewrite the $config array if above solution dose't work. Here sample_simage
is the name of input type.
$allowed_types = 'ogg|ogv';
$config['upload_path'] = './assets/uploads/';
$config['allowed_types'] = substr($allowed_types, strpos($allowed_types,substr($_FILES['sample_simage']['name'], -3)), 3);
$this->load->library('upload', $config);
$this->upload->do_upload('sample_simage');