User.prototype.subirLote = function() {
// Called to upload the file
console.log('XXXX');
$("#arquivoLote").trigger("click");
arquivo = $("#arquivoLote").val();
// The name is empty
console.log('Y ' + arquivo);
};
<?
//------------------------------------------------------------
public function subirLote(Request $request){
//------------------------------------------------------------
$arquivo=$request->file('arquivoLote');
*--- AT THIS POINT THE FILE IS RECEIVED AS: C:\xampp\tmp\php6669.tmp (OR SOMETHING LIKE)
file_put_contents('debug.log', 'Arquivo = '. $arquivo.PHP_EOL , FILE_APPEND);
*-----------------------------------------------------------------------------
Config::set('excel.import.heading', 'slugged_with_count');
Config::set('excel.import.startRow', 1);
try{
$arquivoUrl = AzureStorage::saveFile($arquivo,'arquivos');
$planilha = Excel::selectSheets('Participantes')->load($arquivo)->toArray();
$validacao = $this->validarArquivo($planilha);
if(!$validacao["valido"])
{
return response()->json(new Resultado(false,"",$validacao));
}
$this->processarLote($planilha);
$saida = array (
"mensagem"=>"<div class='alert alert-success text-center'><strong>Sucesso:</strong> Arquivo processado com sucesso!</div>",
"valido"=>true
);
} catch (\Exception $e) {
Debugbar::info($e);
Log::error($e);
$saida = array (
"mensagem"=>"<div class='alert alert-warning text-center'><strong>Informação:</strong> 002 Arquivo de participantes com formato inválido.<br />Por favor, verifique-o antes de continuar</div>",
"valido"=>false
);
}
return response()->json(new Resultado(false,"",$saida));
}
?>
hotsite.InitFileUpload("arquivoLote", "/admin/user/subirLote", pars, resultBatchUpload, failBatchUpload);
$("#arquivoLote").change(function () {
console.log('file to be upload...');
if (jqXHRData) {
jqXHRData.submit();
}
return false;
});
<script>
var jqXHRData;
$(document).ready(function () {
var pars = {
_token:$('input[name="_token"]').val(),
};
var resultBatchUpload = function (data) {
//EF
console.log('ZZZZ');
if (!data.result.erro) {
//$('#visualiza').html(data.result.retorno.retorno);
//EF
console.log('OK');
$('#visualiza').html(data.result.retorno.mensagem);
//EF
//console.log($('#visualiza').html(data.result.retorno.mensagem));
$('#visualiza').show();
if(data.result.retorno.valido){
$('#btnImportar').show();
$('#arquivoImportar').val(data.result.retorno.arquivo);
//EF
console.log('Z1111');
console.log($('#arquivoImportar').val());
} else {
console.log('Z2222');
$('#btnImportar').hide();
$('#arquivoImportar').val('');
}
return true;
} else {
//EF
console.log('PPPP Error');
hotsite.openModalCustom("Erro",'Erro ao subir lote.', "Entendi", "error");
return false;
}
};
var failBatchUpload = function (data) {
if (data.files[0].error) {
hotsite.openModalCustom("Erro",'Erro ao subir a lote.', "Entendi", "error");
return false;
}
};
hotsite.InitFileUpload("arquivoLote", "/admin/user/subirLote", pars, resultBatchUpload, failBatchUpload);
$("#arquivoLote").change(function () {
console.log('arquivo para upload...');
arquivo = $("#arquivoLote").val();
console.log('Y ' + arquivo);
if (jqXHRData) {
jqXHRData.submit();
}
return false;
});
});
</script>
<!-- Modal -->
<div class="modal fade" id="mBatchUser" tabindex="-1" role="dialog" aria-labelledby="mBatchUserLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="mBatchUserLabel">Lote de Participantes</h4>
</div>
<div class="modal-body">
<div class='row'>
<div class='col-md-12 text-center'>
<a href='/content/templates/loteparticipantes.xlsx' class='btn btn-warning'><i class="fas fa-download" aria-hidden="true"></i> Obter Modelo</a>
<button id='btnLote' class='btn btn-primary' onclick='hotsite.user.subirLote();'><i class="fas fa-upload" aria-hidden="true"></i> Carregar Lote de Participantes</button>
<input type='file' id='arquivoLote' name='arquivoLote' style='display:none;'/>
<input type='hidden' id='arquivoImportar' name='arquivoImportar'/>
</div>
</div>
<br/>
<div class='row'>
<div class='col-md-12'>
<div id='visualiza' style="height:400px;overflow:auto;display:none;">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fas fa-times" aria-hidden="true"></i> Fechar</button>
{{-- <button id='btnImportar' onclick='hotsite.user.processarLote();' type="button" class="btn btn-primary"><i class="fas fa-cloud-upload-alt" aria-hidden="true"></i> Importar</button> --}}
</div>
</div>
</div>
</div>
public function subirLote(Request $request){
$arquivo=$request->file('arquivoLote');
Config::set('excel.import.heading', 'slugged_with_count');
Config::set('excel.import.startRow', 1);
try{
$arquivoUrl = AzureStorage::saveFile($arquivo,'arquivos');
$planilha = Excel::selectSheets('Participantes')->load($arquivo)->toArray();
$validacao = $this->validarArquivo($planilha);
if(!$validacao["valido"])
return response()->json(new Resultado(false,"",$validacao));
$this->processarLote($planilha);
$saida = array (
"mensagem"=>"<div class='alert alert-success text-center'><strong>Sucesso:</strong> Arquivo processado com sucesso!</div>",
"valido"=>true
);
} catch (\Exception $e) {
Debugbar::info($e);
Log::error($e);
$saida = array (
"mensagem"=>"<div class='alert alert-warning text-center'><strong>Informação:</strong> Arquivo de participantes com formato inválido.<br />Por favor, verifique-o antes de continuar</div>",
"valido"=>false
);
}
return response()->json(new Resultado(false,"",$saida));
}
Based on your previous question, I would guess that the code you have in Laravel is never told to save the file anywhere - you just request that the file is downloaded by the browser.
Usually, when you do this in PHP, the system just temporarily stores the file before sending it to the browser, which is why you get a tmp filename. The idea behind this is that at some point after the user has downloaded the file, there is no longer a need for it on the server, and the tmp folder can be cleaned up.