With reference to this tutorial. Tracking upload progress with php . I want to make it work in Codeigniter. I am not getting point to start to make it work in CI. I want to upload files and also track progress.
In my CI view
<?php $arr = array("id"=>"myform");
echo form_open_multipart("welcome/uploads",$arr); ?>
<input type="hidden" value="myForm" name="<?php echo ini_get("session.upload_progress.name"); ?>">
<table>
<tr>
<td>file</td>
<td><input type="file" name="images[]" multiple></td>
</tr>
<tr>
<td>name</td>
<td><input type="text" name="naam"></td>
</tr>
<tr>
<td></td>
<td><input type="submit"></td>
</tr>
</table>
<?php echo form_close(); ?>
<div id="bar_blank">
script
function toggleBarVisibility() {
var e = document.getElementById("bar_blank");
e.style.display = (e.style.display == "block") ? "none" : "block";
}
function createRequestObject() {
var http;
if (navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
http = new XMLHttpRequest();
}
return http;
}
function sendRequest() {
var http = createRequestObject();
http.open("GET", "<?php echo base_url().'index.php/welcome/progress' ?>");
http.onreadystatechange = function () { handleResponse(http); };
http.send(null);
}
function handleResponse(http) {
var response;
if (http.readyState == 4) {
response = http.responseText;
document.getElementById("bar_color").style.width = response + "%";
document.getElementById("status").innerHTML = response + "%";
if (response < 100) {
setTimeout("sendRequest()", 1000);
}
else {
toggleBarVisibility();
document.getElementById("status").innerHTML = "Done.";
}
}
}
function startUpload() {
toggleBarVisibility();
setTimeout("sendRequest()", 1000);
}
(function () {
document.getElementById("myForm").onsubmit = startUpload; //error is here
})();
According to above tutorials, its in core php. When submitting form CI request to controller dashboard/addRoom
and my page gets refresh anyhow. But in tutorials, Form redirects to PHP_SELF
(same php file). I am not getting any idea on it. Please help me.
Controller
function progress()
{
session_start();
$key = ini_get("session.upload_progress.prefix") . "myForm";
if (!empty($_SESSION[$key])) {
$current = $_SESSION[$key]["bytes_processed"];
$total = $_SESSION[$key]["content_length"];
echo $current < $total ? ceil($current / $total * 100) : 100;
}
else {
echo 100;
}
}
public function uploads()
{
if(!empty($_FILES['images']['name'][0]))
{
//uploadinf file code
}
}