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
Related
I want to compress the image file size to a max of 100kb, but the user can upload an image with a max size of 4MB, when entering the folder the image size becomes <100kb or max 100kb.
Below is my config code:
$config['upload_path'] = './assets/uploads/STNK/';
$config['allowed_types'] = 'jpg|png|jpeg|JPG|PNG|JPEG';
$config['max_size'] = '4000'; /* users can upload 4MB files */
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if ($this->upload->do_upload('foto_stnk')) {
$old_image = $this->data['row']->foto_stnk;
unlink(FCPATH . './assets/uploads/STNK/' . $old_image);
$new_image = $this->upload->data('file_name');
$this->db->set('foto_stnk', $new_image);
} else {
echo $this->upload->display_errors();
}
Please help, thank you!
You can user imagejpeg() function of php to reduce image quality.
This might help you : imgejpegfunction
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'] = '*';
I have declared enctype="multipart/form-data"
my input type
<textarea class="input-style" name="blog2" placeholder="Para 2"></textarea>
<input type="file" name="blog_img" size="chars" class="upload-file" />
my controller:
function upload()
{
//set preferences
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'txt|pdf';
$config['max_size'] = '100';
//load upload class library
$this->load->library('upload', $config);
if (!$this->upload->do_upload('filename'))
{
// case - failure
$upload_error = array('error' => $this->upload->display_errors());
$this->load->view('upload_file_view', $upload_error);
}
else
{
// case - success
$upload_data = $this->upload->data();
$data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' . $upload_data['file_name'] . '</strong> was successfully uploaded!</div>';
$this->load->view('upload_file_view', $data);
}
}
Perhaps it might be a file upload size issue.
You have to check your PHP configurations on php.ini file. If your upload is constantly being interrupted you either need to increase the maximum upload size or the time before your PHP script times out. Check this variables:
post_max_size
upload_max_filesize
max_execution_time
You can either increase in your PHP configuration file or increase in your script using the ini_set function. Check the manual for more details. PHP Manual
input type='file' needs to be named 'userfile' by default
https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html
You can change the default to yours at
$this->upload->do_upload('filename')
change this to
$this->upload->do_upload('your file input name')
You have
if (!$this->upload->do_upload('filename'))
but in your file input name is blog_img, so us that instead of filename
if (!$this->upload->do_upload('blog_img'))
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('*');
$image = $_FILES['picture']['name'];
$id=$_SESSION['id'];
//This function separates the extension from the rest of the file name and returns it
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
$ext = findexts ($_FILES['picture']['name']) ;
//This assigns the subdirectory you want to save into... make sure it exists!
$target = "mainimage/";
//This combines the directory, the random file name, and the extension
$target = $target . $id.".".$ext;
if(move_uploaded_file($_FILES['picture']['tmp_name'], $target))
{
echo ("This is your new profile picture!");
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
for some reason the "else" keeps showing up (there was a problem uploading the file). I put comments in everything that I am trying to do. please help! thanks!
To close the question as per OP's request.
The issue is that you need to increase the maximum size for uploads. PHP's default is usually 2M and you are most probably trying to upload a file larger than what the maximum setting is set to.
This can be achieved in two ways.
By editing your php.ini file with the following settings:
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
or via an .htaccess file placed in the root of your server:
php_value upload_max_filesize 20M
php_value post_max_size 30M