Other file listed is uploading fine, but swf file is not uploading and giving a error of file type is not supported.
Here is my controller
function do_upload(){
$pid=$this->input->post('Page_id');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'swf|png|gif|jpg';
$config['max_size'] = '1048';
$config['file_name'] =$pid;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/upload', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->upload_success();
}
}
might be a bug with the File Upload Class in the _file_mime_type function
look for more here
You haven't pass the the field name in the do_upload call like
$config = array(
'allowed_types' => 'jpg|jpeg|swf|png', // pipe seperated file types
'upload_path' => './uploads/',// should be the root path
'max_size' => '1048',
'file_name' =>$pid
);
$this->load->library('upload', $config );
if (!$this->upload->do_upload('your_field_name')){
// like $this->upload->do_upload($pid)
$error = array('error' => $this->upload->display_errors());
}else{
$swf_data = $this->upload->data();
}
Hope it makes sense
Related
I have form with 4 file fields and I want to upload these files properly.
My code is as follows :
public function do_upload(){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
} else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
private function fileUpload($name, $config = []){
$config['upload_path'] = './uploads/';
$config['encrypt_name'] = TRUE;
$config['file_ext_tolower'] = TRUE;
$config['allowed_types'] = 'jpg|jpeg|png';
$this->upload->initialize($config);
if ( ! $this->upload->do_upload($name))
{
$error = array('error' => true, 'message' => $this->upload->display_errors());
return $error;
}
else
{
return array('error' => false, 'upload_data' => $this->upload->data());
}
}
Create this private function in the controller just call this function when you have to upload the file with the name of the file field if you want some other config just pass config array to as a next parameter
$data = $this->fileUpload('site_logo_dark')
if($data['error']){
echo data['message']; // error message while uplaoding an file if have any
}else{
echo $data['upload_data']['file_name']; // return you a name of the file which you just upload it you can save it to the database
}
This is a very simple file uploading with CI but the system says functions site_url() or base_url() can't be used in original file Helper Codeigniter
$this->config = array('upload_path' => dirname($_SERVER["SCRIPT_FILENAME"])."/images/",
'upload_url' => base_url()."images/",
'allowed_types' => "png|jpg",
'overwrite' => TRUE,
'max_size' => "10000KB",
'max_height' => "7680",
'max_width' => "10240",
'file_name' => "about"
);
$this->load->library('upload', $this->config);
if($this->upload->do_upload('logo'))
{
$this->session->set_flashdata('success_upload', 'You logo has been uploaded' );
}
else
{
$this->session->set_flashdata('error_upload', 'Can\'t Upload this file, Please try agine.' );
}
Use this code it will helps you.
$obj = &get_instance();
$obj->load->library('upload');
$file_name = "about." . pathinfo($_FILES['logo']['name'], PATHINFO_EXTENSION); //userrandom file name instead of about
$full_path = FCPATH . 'images/';
$config['upload_path'] = $full_path;
$config['allowed_types'] = 'gif|jpg|png|jpeg|GIF|JPG|PNG|JPEG';
$config['max_size'] = 2048;
$config['max_width'] = 2048;
$config['max_height'] = 2048;
$config['file_name'] = $file_name;
$obj->upload->initialize($config);
if (!$obj->upload->do_upload('logo')) {
$this->session->set_flashdata('error_upload', $obj->upload->display_errors());
return $obj->upload->display_errors();
} else {
$this->session->set_flashdata('success_upload', 'You logo has been uploaded');
return $obj->upload->data();
}
don't use dirname() for file path .
use FCPATH it will gile you absolute path from root like "/var/www/html/project_name"
upload_url is not a key in codeiginter upload library
use random file name because if you upload another image it will override or create file new file like file_name(1).extension
As per your this comment I think you have to load the URL helper first.
$this->load->helper('url');
Or you can load it in autoload.php
$autoload['helper'] = array('url');
To Upload the image try this code:
$config['upload_path'] = './images/';
$config['allowed_types'] = 'png|jpg';
$config['max_size'] = 10000;
$config['max_width'] = 10240;
$config['max_height'] = 7680;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
Hi I am trying to upload .ini file in Codeigniter but CI shows me error that this file type is not allowed.
I tried putting this in mimes.php but didn't work :
$mimes = array('ini' => 'application/octet-stream')
My code is:
public function index()
{
$this->load->view('customer/upload/upload_ini', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'ini';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('customer/upload/upload_ini', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('customer/upload/upload_success', $data);
}
}
This solution may work for you but it will
upload all filetypes without any extension check,
$config['allowed_types'] = '*';
May this link will be useful to you.
Hope it will help you :)
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'))
this is a code for swf fiel uploading but the problem is it works fine on localhost but not in the remote server.here is my controller
function do_upload()
{
$pid=$this->input->post('Page_id');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'swf';
$config['max_size'] = '1048';
$config['file_name'] =$pid;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
}
else{
$data=array(
'id'=>$pid,
'link'=>base_url()."uploads/",
'file_name'=>$config['file_name']
);
$this->file_upload_model->upload_data($data);
$this->upload_success();
}
}
i have not done anything except just uploading the path and file name to the database in model. see the demo here
Try this
$pid=$this->input->post('Page_id');
$config['file_name'] = $pid;
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'swf';
$config['max_size'] = '1048';
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if ($this->upload->do_upload())
{
//upload successful
//do something
}
else
{
$this->session->set_flashdata('error',$this->upload->display_errors());
redirect('controller/method');
/*
In the view file you can echo the error like this
echo $this->session->flashdata('error');
*/
}
You have pass the the field name in the do_upload call like this:
$config = array(
'allowed_types' => 'jpg|jpeg|swf |png', // pipe seperated file types
'upload_path' => './uploads/', // should be the root path
'max_size' => '1048',
'file_name' => $pid
);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('your_field_name')) {
// like $this->upload->do_upload($pid)
$error = array('error' => $this->upload->display_errors());
} else {
$swf_data = $this->upload->data();
}
Hope it makes sense
it may be due to PHP server version and it's option.
1).go to cpanel account
2).click "select php version", in the software section.
3).tap the "fileinfo" chexbox in the php option and save.
now you can upload file perfectly.