I am getting this error:
The upload destination folder does not appear to be writable.
But is_dir and is_writable both return true.
$config['upload_path'] = './work_order_doc/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']= '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$work_order_file="work_order_file";
var_dump(is_dir($config['upload_path']));
var_dump(is_writable($config['upload_path']));
if ( ! $this->upload->do_upload($work_order_file))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
$temp="";
}
else
{
$upload_data = $this->upload->data();
echo $temp=$upload_data['file_name'];
}
Maybe your host have blocked file uploads?
You can always try to specify full path to the upload directory.
Your PHP configuration may be not allowing you to get to the file/directory, try checking open_basedir in php.ini and make sure it is in allowed paths.
Related
Unable to upload these formate file in codeigniter STEP, STP, IGES, IGS, SLDPRT, 3DM, SAT or X_T
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf|step';
$config['max_size'] = 100000000000;
//$config['max_width'] = 1024;
// $config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('fileUpload'))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
// echo 'error';
// $this->load->view('upload_form', $error);
}else{
$this->upload->data();
}
error :- The filetype you are attempting to upload is not allowed
for those file types, just change your config of allowed_types into this to override checking extension:
$config['allowed_types'] = "*";
Before uploading your file, codeigniter check your file's extension first, but your file types are not in application/config/mimes.php so codeigniter does not know and then always return FALSE.
Another way is to add your mimes type into mimes.php, you can check out this in this link
I am uploading file in codeigniter using
$this->upload->do_upload('image')
but when file moves to particular path the file extension is changed (it's changed to lower case)
for example if I upload file "profile.JPG" it's changes to "profile.jpg"
please change CI system library
default in CI upload library $file_ext_tolower = FALSE.
.system\libraries\upload.php
public $file_ext_tolower = TRUE;
do_upload does this
$config['allowed_types'] = 'gif|jpg|png'
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())
{
$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);
}
}
If you want to use same name / extension you send to save your file. You can use :
$upload_dir= $this->config->item("upload_dir");
$fileName = $_POST['sku_code'].".".$extension;
$filePath = $upload_dir.$fileName;
move_uploaded_file($_FILES["image-file"]["tmp_name"],$filePath );
Useful link :
https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html
I have the following code in a controller function (this is CI):
if(!empty($_FILES['filename']) && is_uploaded_file($_FILES['filename']['tmp_name'])) {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->upload->overwrite = true;
if ( ! $this->upload->do_upload('filename')){
$error = array('error' => $this->upload->display_errors());
var_dump($error);
exit;
}
else {
$this->upload->do_upload('filename');
$upload_info = $this->upload->data();
var_dump($upload_info);
exit;
}
}
This should work, it return no errors, and returns the $upload_info array before I exit(); (exit is here for debugging). The $upload_info array suggests that the file has been passed to the correct path on the server. The folder permissions are set to 777 on this folder.
However, the file does not appear on the server! Could anyone suggest what the issue might be here. All the correct libraries have also been loaded.
You call for $this->upload->do_upload('filename') twice.
First time in if and then second time in else-branch.
You should remove second $this->upload->do_upload('filename').
Final code:
if ( ! $this->upload->do_upload('filename')){
$error = array('error' => $this->upload->display_errors());
var_dump($error);
exit;
}
else {
$upload_info = $this->upload->data();
var_dump($upload_info);
exit;
}
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('*');
Can't upload file. $this->upload->do_upload('anonsphoto'); returns false. Can't find out why.
I added upload library to autoload this way: $autoload['libraries'] = array('upload');
Here is my view:
<?php
echo form_open_multipart('InterviewController/saveInterview');
$anons_data = array(
'name' => 'anons',
'id' => 'anons_area',
'value' => 'Введите анонс'
);
echo form_textarea($anons_data); ?>
<p>Картинка анонса</p>
<?php
echo form_upload('anonsphoto'); ?>
Here is controller which uploads file:
public function saveInterview() {
$config['upload_path'] = '/application/upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['file_name'] = 'img_' . (string) time();
$this->upload->initialize($config);
$this->upload->do_upload('anonsphoto');
return;
}
Uploading file is 3 kb sized png file. I can't understand why do_upload is returning false. Any ideas?
File uploading class says all what you need. https://www.codeigniter.com/userguide3/libraries/file_uploading.html
This is a key:
$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);
// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);
"." (dot) means currently directory of upload path. So your app is not working because you are on root path not started with (dot).
Your folder should be with full permission (CHMOD) to 0755.
This:
$config['upload_path'] = './uploads/';
means: currently directory and to uploads directory
or:
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/application/upload/';
means: your full document URI path and on directory '/application/upload/' as Can says.
Don't forget to put (dot) . between $_SERVER['DOCUMENT_ROOT'] and '/application/upload'.
Max size should be in KiB values: $config['max_size'] = '10000';
Hope this helps for understanding how it works.
I think your upload path is wrong. try using
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/application/upload/';
and make sure that the directory is writable.