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.