Upload progress – uploadprogress_get_info nefunguje

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
fliper333
Člen | 36
+
0
-

Zdravim,

Mam mensi problem s dibi formularom a PHP funkciou uploadprogress_get_info. Nevracia mi aktualnu hodnotu uploadu, ale stale vracia false – ako keby neropoznal identifikator. Je mozne ze nette odosiela formular nejakym inym sposobom ktory brani tejto funkcii aby fungovala?

Formular:

public function __construct()
{
    $this->_uid = md5(uniqid(mt_rand()));
    $this->_form = $this->generateForm();
    $this->processForm();
}

protected function generateForm()
{
    $form = new NForm('upload');
    $form->setAction('index.php?go=' . self::$_go . '&goSub=' . self::$_goSub);

    $form->addHidden('id_user', self::$_idUser)
        ->setHtmlId('id_user');

    $form->addHidden('UPLOAD_IDENTIFIER', $this->_uid)
        ->setHtmlId('uid');

    $form->addUpload('file_upload')
        ->setHtmlId('file_upload')
        ->getControlPrototype()->class('file');

    $form->addSubmit('submit', self::$_langData['upload'])
        ->getControlPrototype()->onclick('uploadProgress()');

    return $form;
}

Zistenie stavu uploadu

if (isset($_GET['uid']))
{
    // Fetch the upload progress data
    $status = uploadprogress_get_info($_GET['uid']);

    if ($status)
    {
        // Calculate the current percentage
        echo round($status['bytes_uploaded'] / $status['bytes_total'] * 100);
    } else {
        // If there is no data, assume it's done
        echo 100; -> skrpt stale vracia toto
    }
}

JavaScript

<script>

    $(function () {
        $('body').append('<div style="margin-top:300px;" id="upload-progress"><span style="text-align:center; margin:auto; font-size:24px; font-weight:bold; display:block; font-family: Tahoma;">Uploading File...</span><div id="progressbar"></div>');
        $('#upload-progress').hide();
        $('#progressbar').progressbar();
        $('#progressbar').css('height', '40px');
        $('#progressbar').css('margin-top', '10px');
    });

    function uploadProgress() {
        $('#wrap').hide();
        $('#upload-progress').show();
        $('body').css('background-image', 'none');
        $('body').css('background-color', '#ffffff');
        $('body').css('font-size', '1.1em');
        $('body').css('padding-left', '8px');
        $('body').css('padding-right', '8px');
        $('#progressbar').progressbar('value', 0);

        setInterval(function () {
            updateProgress($('#uid').val());
        }, 100);
    }

    function updateProgress(id) {
        var time = new Date().getTime();
        $.get('ajax/getUploadProgress.php', { uid: id, t: time }, function (data) {
            var progress = parseInt(data, 10);
            console.log(data);
            $('#progressbar').progressbar('value', progress);
        });
    }

</script>

Ak skopirujem vygenerovany nette formular a dam ho do stranky „napevno“, tak skript funguje bez problemov.

Dakujem vopred za rady.

fliper333
Člen | 36
+
0
-

Tak sa mi podarilo problem vyriesit. Chyba bolo v tom, ze vo formulari musi byt UPLOAD_IDENTIFIER pred file, nette generuje formulare tak, ze hidden inputy dava az uplne na koniec.

https://bugs.php.net/bug.php?…

Snad niekomu pomoze