Upload file size in codeigniter - php

I need to upload the 11 mb mp3 file using do_upload in codeigniter.
My upload function :-
$config['upload_path'] = FCPATH . 'uploads/mp3';
$config['allowed_types'] = 'mp3';
$config['max_size'] = '1024*20';
$this->load->library("upload", $config);
$image_data = $this->upload->data();
My php.ini
post_max_size : 32M
memory_limit : 128M
max_execution_time :120
But I cant' upload 11mb mp3 file . But less than 8 mb its working fine. Please help how can I fix this .
The error in the php error log is :-
{"file_name":false,"error":["<p>The filetype you are attempting to upload is not allowed.<\/p>"]}

$config['allowed_types'] = 'mp3';
This line mean you can only upload files in mp3 format.
This error means your file is not mp3 format.
change
$config['allowed_types'] = 'mp3';
to
$config['allowed_types'] = '*';

Related

Why can't I upload zip type file?

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.

Upload the mp3 file in the folder?

I want to upload the mp3 file but it shows the message of :
"The uploaded file exceeds the maximum allowed size in your PHP configuration file."
my file is only 4.5 mb and this is my controller:
public function add_audio(){
$config['upload_path'] = './musics/';
$config['allowed_types'] = 'mp3|3gp|mpeg';
$config['max_size'] = '999999999999999999999';
$this->load->library('upload',$config);
chmod('musics/', 0777);
$this->upload->do_upload();
$data['audio'] = $_FILES['userfile']['name'];
if ( ! $this->upload->do_upload())
{
$data['error'] = $this->upload->display_errors();
print_r($data['error']);
//line of codes that displays if there are errors
}
else
{
$data['audio'] = $_FILES['userfile']['name'];
$this->load->model('main');
$query = $this->main->insert('audio',$data);
if($query == TRUE){
$this->load->view('admin/success');
}
}
}//end add
need help...
You need to increase upload_max_filesize and post_max_size in your php.ini. After change, restart http server to use new values.
; Maximum allowed size for uploaded files.
upload_max_filesize = 5M
; Must be greater than or equal to upload_max_filesize
post_max_size = 5M

Codeigniter Image upload ignore allowed types and file size

I have below code to upload user image, my code work good but I'm getting issue while checking allowed_types i.e. png|jpg and max_size..
It doesn't check allowed type and max size
Code:
$this->load->library('upload');
$config['upload_path'] = 'admin/upload/';
$config['allowed_types'] = 'jpg|jpeg';
$config['max_size'] = '100';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->set_allowed_types('*');
if (!$this->upload->do_upload('user_image')){
$data = array('msg' => $this->upload->display_errors());
$flag="1";
}else {
$image_path = $this->upload->data();
$flag="2";
}
Output:
$flag always set to 2...even I uploaded file .png or .gif and same problem for max_size
Try increasing the max_size. Also remove the line $this->upload->set_allowed_types('*');

PHP File Uploading working in local but not working in server

As I'm uploading a csv file in localhost it is correctly working. All the validations are done but while uploading the file online it is not working. The file is refreshing itself.This is my sample code
$data['error'] = ''; //initialize image upload error array to empty
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'csv';
$config['max_size'] = '10000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
$data['error'] = $this->upload->display_errors();
$data['mainpage']='category';
$data['mode']='addcsv';
$this->load->view('includes/mainpage',$data);
}
else
{
$file_data = $this->upload->data();
$file_path = './uploads/'.$file_data['file_name'];
Please check your write permission to the directory you want to upload.
Are you getting any error messages thrown while uploading the file?
Also make sure that you have set the correct permissions to the upload directory you are trying to upload the file to.
It would also be nice with some code.
Use move_uploaded_file() function like below
move_uploaded_file($_SERVER['DOCUMENT_ROOT'].'/'.$_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
What's the output of $this->upload->display_errors(); ?
You can also check the folder permissions on the server (0777)

how can I change allowed file type in codignetor which actually work?

Here is my controller code but only jpg and png file are uploaded I also changed it my process model.php also.
Is there any way to change it? And it doesn’t show any warning. You can check it from here but you need to register first...
public function saveTestimonial() {
$config['upload_path'] = './testimonial_photo/';
$config['allowed_types'] = 'gif|jpg|png|psd|zip|tif|ai|eps';
$config['max_size'] = '1024';
$config['max_width'] = '10240';
$config['max_height'] = '7680';
You should declare file upload like the below code. Since you are uploading images, docx, zip files you should not declare max_width and max_height. But you can change the max_size for the file.
$config['upload_path'] = 'testimonial_photo/';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->set_allowed_types('gif|jpg|png|jpeg|zip|pdf|doc|docx');
$this->upload->do_upload('filename_in_html_input')

Categories