I work on a module which convert xlsx to csv and doing some stuff on database, I did it with PHP but now I have to do it with CodeIgniter.
Here is my main issue :
I have some "infinite loading" while pressing upload button, and nothing is happening.
Here is my controller
public function convert(){
$config['upload_path'] = FCPATH.'views/admin/traitement_xslx/csv';
$config['allowed_types'] = 'xlsx|csv|xls';
$config['max_size'] = '1000000000';
$config['overwrite'] = true;
$config['encrypt_name'] = FALSE;
$config['remove_spaces'] = TRUE;
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('xlsxfile'))
{
echo 'no';
}
else
{
echo 'ok';
}
}
And this is my view
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<?php echo $redir; ?>
<script type="text/javascript">
function message(){
document.getElementById("msg").innerHTML="Conversion<blink>... </blink>";
}
</script>
</head>
<body >
<div id="container" style="display:inline-block;">
<h3 class="alert" id="msg"><?php echo $alert; ?></h3>
<p>Selectionnez un fichier XLSX à convertir et traiter :</p>
<form action="<?= site_url('admin/Traitement_doublons/convert'); ?>" method="post" enctype="multipart/form-data">
<input type="file" name="xlsxfile" size="40" />
<input type="hidden" name="convert">
<br />
<br />
<input type="text" name="throttle" id="throttle" value="0" onkeyup="this.value=this.value.replace(/[^\d]/,\'\')" size="5"> # de lignes à convertir (0 = No limit) <br />
<br />
<input type="submit" class="button" name ="upload" onClick="message()" value="Convertir en CSV et traiter" />
</form>
</div>
<div id="container" style="display:inline-block;">
<h3 class="alert" id="msg"><?php echo $alert2; ?></h3>
<p>Où un fichier CSV à seulement traiter :</p>
<form action="#" method="post" enctype="multipart/form-data">
<input type="file" name="csvfile" size="40" />
<input type="hidden" name="convertcsv">
<br />
<br />
<input type="text" name="throttlecsv" id="throttle" value="0" onkeyup="this.value=this.value.replace(/[^\d]/,\'\')" size="5"> # de lignes à convertir (0 = No limit) <br />
<br />
<input type="submit" class="button" name = "uploadcsv" onClick="message()" value="Traiter les données" />
</form>
</div>
<div>
<p><?php if(isset($_SESSION['champs']['total'])){ echo $_SESSION['champs']['total']; }?></p>
<p><?php if(isset($_SESSION['champs']['inseres'])){ echo $_SESSION['champs']['inseres']; }?></p>
<p><?php if(isset($_SESSION['champs']['doublons'])){ echo $_SESSION['champs']['doublons']; }?></p>
</div>
</body>
</html>
Any ideas ? Thanks
First, check if($_FILES['csvfile']['size'] > 0) , add name to your file $config['file_name'] = $new_name; and then give the name of input file name to your do_upload function if ( ! $this->upload->do_upload('csvfile')).