Di tanti esempi, ne ho riadattato uno.
index.html
<p id="progress-txt"></p>
<form action="upload.php" method="POST" enctype="multipart/form-data" id="upload">
<input type="hidde" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="123" />
<div class="clearfix">
<label for="file1">File 1</label>
<div class="input">
<input type="file" name="file1" id="file1" />
</div>
</div>
<div class="clearfix">
<label for="file2">File 1</label>
<div class="input">
<input type="file" name="file2" id="file2" />
</div>
</div>
<div class="actions">
<input type="submit" class="btn primary" value="Upload"/>
</div>
</form>
<script>
//Holds the id from set interval
var interval_id = 0;
$(document).ready(function(){
alert('o vai!');
//jquery form options
var options = {
success: stopProgress, //Once the upload completes stop polling the server
error: stopProgress
};
//Add the submit handler to the form
$('#upload').submit(function(e){
alert('cliccato!');
//check there is at least one file
if($('#file1').val() == '' && $('#file2').val() == '')
{
e.preventDefault();
return;
}
//Poll the server for progress
interval_id = setInterval(function() {
$.ajax({
type: "POST",
url: 'progress.php',
async:false,
dataType: 'html',
error: function (jqXHR,xhr, ajaxOptions, thrownError)
{
alert('errore');
},
success: function(response)
{
// alert('response='+response);
$('#progress-txt').html(response);
}
})
}, 200);
$('#upload').ajaxSubmit();
e.preventDefault();
});
});
function stopProgress()
{
clearInterval(interval_id);
}
</script>
upload.php
<?php
session_start();
var_dump($_SESSION);
var_dump($_FILES);
?>
progress.php
<?php
session_start();
echo print_r($_SESSION);
?>
nel print_r(S_SESSION) non restituisce niente, da un array vuoto