Codeigniter - upload not working in 000webhost - php

The codeigniter do_upload function would not work in 000webhost.
I had already set the uploads folder permission to 777.
If I do it in XAMPP, it will work but in 000webhost ftp it wouldn't.
The following section shows my code:
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'xls|xlsx';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
redirect('customer/viewCustomer');
}
else
{
$data = array('upload_data' => $this->upload->data());
echo "success";
}
$upload_file = $this->upload->data();
}

Related

i was trying to upload a zip file using php codigniter

I have many doubts regarding this.
In autoload.php, in $autoload[libraries] what library should specify for
uploading the file.
When I took a reference, I saw using
$this->load->library('upload', $config);
and there is no library named upload in my files.
3. Below is my controller
function cpanel_download_or_upload()
{
if(isset($_POST[TAG_UPLOAD]))
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'zip';
if ( ! is_dir($config['upload_path']) ) die("THE UPLOAD DIRECTORY DOES NOT EXIST");
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile')) {
die("ERROR");
} else {
return array('upload_data' => $this->upload->data());
}
}
$this->load->view('CPANEL/access_file_from_or_to_cpanel.php');
}

change permission folder Codeigniter

I want to change the permission for a folder (big_pics) to mode 777.
function do_upload(){
$config['upload_path'] = './big_pics/';
$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('')){
$error = array('error' => $this->upload->display_errors());
foreach($error as $key => $value){
echo $value."<br>";
}
//$this->load->view('upload_form', $error);
}else{
echo "Well DOne";
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
The folder is positioned on root folder.
I use codeigniter for this project
You can change the permission of your file or folder by using this before upload.
$frdata = array('upload_data' => $this->upload->data()); // get data
$frfile = $frdata ['upload_data']['full_path']; // get file path
chmod($frfile, 0777); // CHMOD file
if(!$this->upload->do_upload('file')) {
echo $this->upload->display_errors();
} else {
$file_name = $this->upload->data();
}

How do i upload .ini file in codeigniter?

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 :)

How to get file upload progress from the code igniter?

I just want to get the file upload progress in code Igniter.Please don't recommend any j-query integration as it is not the matter right now. Just give me a plain solution that could be done to get file progress in code igniter.
This is my code to uplaod pictures:
$base=$this->config->item('base_url');
$images=$this->config->item('images');
$config['upload_path'] = './images/teacherimages';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
echo "Error<br>";
}
else
{
$data = array('upload_data' => $this->upload->data());
$upload_data = $this->upload->data();
$pic = $upload_data['file_name'];
$this->load->model('Teacher/InsertModel');
$this->InsertModel->updatePic($pic,$id);
}

codeigniter file is not uploading on remote server

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.

Categories