How to give include in page js to make progressbar and return to php

0

Hello, I have a system to upload a file and then put the data in the database.

<form enctype="multipart/form-data" method="post" class="formSendTorrent" id="formSendTorrent" name="formSendTorrent">

        <div class="defaultStyleSend fontDefault">
            <input type="file" multiple name="inputfileSendTorrent[]" id="inputfileSendTorrent"> 
        </div>
        <div id="progressBarCurrent">
            <div id="progbar"></div>
        </div>

        <input type="submit" name="submitSendTorrent" class="submitSendTorrent" value="Enviar">
    </form>

<?php
require DIR_FUNCS.'funcSQL.php';
require_once DIR_FUNCS.'Torrent.php';

if(isset($_POST['submitSendTorrent']))
{   
    echo 'começo';

    $i = 0;

    $uploaddir = DIR_ARQUIVOS.$chave.'/';

    include DIR_FUNCS.'progressBar.js';

    foreach ($_FILES["inputfileSendTorrent"]["error"] as $key => $error) 
    {
        $arqName = $_FILES['inputfileSendTorrent']['name'][$i];
        $arqTemp = $_FILES['inputfileSendTorrent']['tmp_name'][$i];

        if(!@move_uploaded_file($arqTemp, $uploaddir.$arqName))
        {
            $error = error_get_last();
            echo $error['message'];
        }

        $i++;
    }

    echo 'final';
} 
?>

progressBar.js

$(function() 
{
    var bar = $('.bar');
    var percent = $('.percent');
    var status = $('#status');

    $('form').ajaxForm(
    {
        beforeSend: function() {
            status.empty();
            var percentVal = '0%';
            bar.width(percentVal);
            percent.html(percentVal);
        },
        uploadProgress: function(event, position, total, percentComplete) 
        {
            document.getElementById("progressBarCurrent").style.display = 'block';
            var total_perc = total | 0;
            var current_perc = position | 0;
            document.getElementById("progbar").innerHTML = Math.floor((current_perc / (total_perc / 100)) * 100) / 100 + '%';
            document.getElementById("progbar").style.width = current_perc / (total_perc / 100) + '%';
        },
        complete: function(xhr) {
            status.html(xhr.responseText);
        }
    });
}); 

Include does not work, but if I put progressBar.js on the same page it makes the right progress, but it does not run php.

I want to run PHP, and just the moment it is uploaded it makes progress on the toolbar, the above code is summarized to better understand, but in the original code I test before uploading the file.

    
asked by anonymous 02.03.2017 / 03:56

1 answer

0

You're mixing garlic with bugs ... by doing the include of the progressBar.js file inside php, basically you are telling the interpreter what he has to do is to read the file progressBar.js as if he had php code, and this is not what you want

What you have to do is in your html to use the script tag with src pointing to the path of your progreebar.js file

I did not look at the rest of your code, but I assume your script is well done

    
02.03.2017 / 04:11