I googled and saw that there are some plugins that do this. But would not want to use plugin because my only problem is this. Through Yii is possible in the session variable to obtain data regarding the progress of uploading a file?I'm making a system that uses php and Yii framework. I'm building a module to upload files. Everything is working perfectly except the display of the progress bar.
I researched and found that the version of PHP 5.4 has the capability forward: Session Upload Progress (http://php.net/manual/en/session.upload-progress.php)
I enabled this setting in my php.ini. I am using File Upload plugin to assist in the client side to perform file uploads. (github.com/blueimp/jQuery-File-Upload)
I want to run the following code:
Client side:
$('#fileupload').bind('fileuploadsend', function(e, data) {
// This feature is only useful for browsers which rely on the iframe transport:
if (data.dataType.substr(0, 6) === 'iframe') {
// Set PHP's session.upload_progress.name value:
var progressObj = {
name : 'PHP_SESSION_UPLOAD_PROGRESS',
value : (new Date()).getTime()
// pseudo unique ID
};
data.formData.push(progressObj);
// Start the progress polling:
data.context.data('interval', setInterval(function() {
$.get(yii.baseUrl + '/atl/default/progressUpload', $.param([progressObj]), function(result) {
// Trigger a fileupload progress event,
// using the result as progress data:
e = $.Event('progress', {
bubbles : false,
cancelable : true
});
$.extend(e, result);
($('#fileupload').data('blueimp-fileupload') || $('#fileupload').data('fileupload'))._onProgress(e, data);
}, 'json');
}, 1000)); // poll every second
}
}).bind('fileuploadalways', function(e, data) {
clearInterval(data.context.data('interval'));
});
$('#fileupload').fileupload({
dataType : 'json',
axFileSize : 500000000,
forceIframeTransport : true,
add : function(e, data) {
data.context = $('<button/>').text('Upload').appendTo(document.body).click(function() {
data.context = $('<p/>').text('Uploading...').replaceAll($(this));
data.submit();
});
},
done : function(e, data) {
alert("done!");
},
progressall : function(e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
console.log(e, data, progress);
$('#progress .bar').css('width', progress + '%');
}
});
Server Side:
public function actionProgressUpload($PHP_SESSION_UPLOAD_PROGRESS) {
$s = Yii::app()->session['upload_progress_'.intval($PHP_SESSION_UPLOAD_PROGRESS)];
$progress = array(
'lengthComputable' => true,
'loaded' => $s['bytes_processed'],
'total' => $s['content_length']
);
echo json_encode($progress);
}
My problem:
Yii in the $ _SESSION variable always returns null, the variable Yii::app()->session does not return me the values for upload progress.
I googled and saw that there are some plugins that do this. But would not want to use plugin because my only problem is this. Through Yii is possible in the session variable to obtain data regarding the progress of uploading a file?
Thanks.
Yii::app()->session['upload_progress_'.intval($PHP_SESSION_UPLOAD_PROGRESS)]before you obtained its value?'upload_progress_' . intval(...)session key was initialized?