My problem is that I have a code that works on localhost but not on production server. I want to upload a file through a form. In localhost everything works fine, but on production server, I get the 'you did not select a file to upload' error.
The view part
<?php echo form_open_multipart('Ajax/do_upload');?>
<input type="file" name="file">
<input type="submit" name="submit" value="upload image" />
<?php echo form_close();?>
The controller part (controller Ajax, function do_upload)
public function do_upload(){
$config['upload_path'] = './assets/images/usr_uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 5000;
$config['max_width'] = 2048;
$config['max_height'] = 2048;
$config['overwrite'] = true;
$this->load->library('upload', $config);
$this->upload->initialize($config);
$filename = $_FILES['file']['name'];
if (!$this->upload->do_upload("file")){
//$data['error'] = "An error occurred while uploading the image.";
$error = array('error' => $this->upload->display_errors());
//echo $filename;
print_r($_FILES);
$this->load->view('template/head.php');
$this->load->view('profileview.php', $error);
$this->load->view('template/footer.php');
} else {
$filename = $_FILES['file']['name'];
$data['up_ok'] = $filename;
print_r($_FILES);
$this->savefn($filename);
$this->updatesesssion();
$this->load->view('template/head.php');
$this->load->view('profileview.php', $data);
$this->load->view('template/footer.php');
}
}
.htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
So the problem is that when on production server, it does not get any file from the form. On localhost it works as it should. I cannot find the cause of this problem and I have tried almost everything I have found. I have also tried with the default userfile, which again works on localhost but not on server and I have already set the folder permissions to 777.
$config['base_url']value set well?.htaccesstoo?$this->upload->initialize($config);