I have tried every possible method but no success. Just trying to upload file using code igniter but not working the error I am getting
<pre>Array
(
[error] => <p>You did not select a file to upload.</p>
)
I have tried in normal core php at my local host that works fine but not working with code igniter. It is simply not picking the file. If I check with var_dump($_FILES['fileToUpload']); the result will be array(0).
Form Code
<form id="contact_form" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>Main/do_upload">
<input type="file" class="form-control" name="fileToUpload" id="fileToUpload">
</form>
Controller Code
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
echo "<pre>";
var_dump($data);
// $this->load->view('upload_success',$data);
}else{
$error = array('error' => $this->upload->display_errors());
echo "<pre>";
print_r($error);
}
config
$autoload['libraries'] = array("session", "email", "database");
$autoload['helper'] = array("url", "file", "form");
Is there anything I am not aware of ? Please guide I am stuck here.
You missed input file name in do_upload():
Use :
if(!$this->upload->do_upload('image_file'))
{
//$this->upload->display_errors()
}
else
{
//$this->upload->data()
}
Instead of:
if($this->upload->do_upload())
You miss parameters in $this->upload->do_upload Pleas check below code.
public function do_upload(){
$config = array(
'upload_path' => "assets/uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('fileToUpload'))
{
$data = array('upload_data' => $this->upload->data());
echo "<pre>";
var_dump($data);
// $this->load->view('upload_success',$data);
}else{
$error = array('error' => $this->upload->display_errors());
echo "<pre>";
print_r($error);
}
}
Pass your file upload name in $this->upload->do_upload('fileToUpload')
Related
A Problem was encountered while attempting to move the uploaded file to the final destination
Unable to upload the file in codeigniter using their upload class, upload directory is also exist,
below is a code
$config = array(
'upload_path' => './upload_dir/users_docs/',
'allowed_types' => 'gif|png|jpeg',
'max_size' => 0,
'max_width' => 0,
'max_height' => 0,
'file_name' => $this->currTime,
);
$this->load->library('upload', $config);
if (!empty($_FILES['company_logo']['name']) && !$this->upload->do_upload('company_logo')) {
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error_message', $error['error']);
redirect('home');
}
$data = array('upload_data' => $this->upload->data());
There was an issue in the 'file_name' => $this->currTime, the format of time was not correct, Apostrophe where coming in the filename var, I just changed it to something else, now it's working, Thank you
I am trying to upload an image via codeigniter but constantly recieve the following message: 'You did not select a file to upload'.
I have viewed many SO answers on this but nothing has helped:
PHP config max File upload size: 2M (I tested with 0.5mb files)
Form is multipart
Website is on localhost
HTML:
<h3>Upload profile image</h3>
<div data-role="fieldcontainer">
<form action='do_upload_prof' method='post' enctype="multipart/form-data">
<input type="file" name='file'>
<input type='submit' value='upload' />
</form>
</div>
PHP Controller:
public function do_upload_prof() {
$config = array(
'upload_path' => "./profile_img/",
'allowed_types' => "gif|jpg|png|jpeg",
'overwrite' => TRUE,
'max_size' => "4048000",
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if ($this->upload->do_upload('file')) {
$data = array(
'upload_data' => $this->upload->data()
);
$this->load->view('header');
$this->load->view('profile', $data);
$this->load->view('footer');
} else {
$error = array(
'error' => $this->upload->display_errors()
);
$this->load->view('header');
$this->load->view('profile', $error);
$this->load->view('footer');
}
}
I am using code-igniter to upload files with two input boxes .
But my code not uploading both the files i m getting same file two times.
please take a look my code -:
**//html**
<?php echo form_open_multipart('vipul/do_upload');?>
<?php echo "<input type='file' name='userfile' size='20' />"; ?>
<?php echo "<input type='file' name='userfile1' size='20' />"; ?>
<?php echo "<input type='submit' name='submit' value='upload' /> ";?>
<?php echo "</form>"?>
in controller
public function do_upload(){
foreach ($_FILES as $keys=>$values){
if($keys == 'userfile1'){
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => false,
'max_size' => "20480000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768000",
'max_width' => "1024000"
);
$this->upload->initialize($config);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{ $data = array('upload_data' => $this->upload->data());}
else{ $error = array('error' => $this->upload->display_errors()); }
}
if($keys == 'userfile'){
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => false,
'max_size' => "20480000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768000",
'max_width' => "1024000"
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{ $data = array('upload_data' => $this->upload->data()); }
else{ $error = array('error' => $this->upload->display_errors()); }
}
}
Please change your PHP code and try this out
$this->upload->do_upload()
to
$this->upload->do_upload($field_name)
where $field_name is your input name attribute.
please check CodeIgniter's File Uploading Class
I am using CodeIgniter file uploading class to upload a image. But if I try and select a pdf instead of image I do not get any errors on form submission.
relevant code
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->article_path.'/magazine',
'max_size' => 2000
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$this->upload->display_errors();
$image_data = $this->upload->data();
It is because you never went to the documentation (here), please do so in order to perform better in CodeIgniter framework.
this should give you heads up (please read comments)
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->article_path.'/magazine',
'max_size' => 2000
);
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload()) //important!
{
// something went really wrong show error page
$error = array('error' => $this->upload->display_errors()); //associate view variable $error with upload errors
$this->load->view('upload_form', $error); //show error page
}
else
{
//all is good we upload
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
Ok try to upload file for hours but i get error,
You did not select a file to upload.
my code is in CI
$this->config = array(
'upload_path' => dirname($_SERVER["SCRIPT_FILENAME"])."/uploads/",
'upload_url' => base_url()."uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf|doc|xml",
'overwrite' => TRUE,
'max_size' => "1000KB",
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $this->config);
if($this->upload->do_upload('logo'))
{
echo "file upload success";
}
else
{
echo $this->upload->display_errors();
}
in view i have
<input type="file" name="logo"/>
when i print_r $_POST i get
Array ( [name_srpski] => tyre [name_english] => Client nametre [logo] => cipele-plava_1.jpg )
Where could be error its very important
Try the following in config:
'upload_path' => FCPATH . "/uploads/", // or use "./uploads/" instead
'max_size' => "1000", // remove the kb from the string. it requires only the number
Try changing $this->load->library('upload', $this->config); to
$this->load->library('upload');
$this->upload->initialize( $this->config );
Also the form type should be multipart
<form method="post" action="some_action" enctype="multipart/form-data" />