0
Hello,
I am developing a financial system for client companies that I already own. I am using angular and php. In this system, I have a part that needs to import data in excel. I’m having trouble getting the file and the company ID to send the comic. NOTE: I already have the php code that moves the file to another folder and turns the xlsx into csv.
<button type="file" ngf-select="uploadFiles($file, $invalidFiles)"
accept="*/*" ngf-max-height="1000" ngf-max-size="1MB">Select File</button>
<?php
include_once("con.php");
$pdo = conectar();
$id_empresa = $_POST['id_empresa'];
include_once("PHPExcel/Classes/PHPExcel.php");
$uploadDir = "uploadFile/";
$uploadfile = $uploadDir . $_FILES['arquivo']['name'];
if(move_uploaded_file($_FILES['arquivo']['tmp_name'], $uploadfile)) {
echo "Dados pegos com sucesso.";
}else{
echo "Não foi possível pegar arquivo";
}
?>
JS
app.controller('AppController', ['$scope', '$window', 'Upload', function($scope, $window, Upload) {
$scope.uploadFiles = function(file, errFiles) {
$scope.f = file;
$scope.errFile = errFiles && errFiles[0];
file.id_empresa = $window.localStorage.getItem("idemp");
id_empresa = $window.localStorage.getItem("idemp");
if (file) {
console.log(file);
file.upload = Upload.upload({
url: 'http://localhost:8888/sistemas/webApps/fluxo_de_caixa/fluxojoin_2.0/php/importaArquivo.php',
method: 'POST',
data: {'id_empresa': id_empresa}
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
});
}, function (response) {
if (response.status > 0)
$scope.errorMsg = response.status + ': ' + response.data;
}, function (evt) {
file.progress = Math.min(100, parseInt(100.0 *
evt.loaded / evt.total));
});
}
}
}]);
Where does the id_company come from? What comes from
$_FILES['arquivo']['name']
? It is appropriate to pass this variable throughbasename
to get only the file name.– foxtrot
The id_company comes from the angular controller. Already in $_FILES['file']['name'], it doesn’t come come, because I can’t catch it at the angle and go to php, understand @Foxtrot? This $_FILES is from an old system that is only in php
– GustavoSevero
Your problem is clearly in the javascript part, please post the function
salvarArquivo
so we can see how this one looks. And please read this https://answall.com/help/mcve, whenever you ask ask ask for an example that we can reproduce the problem, you assumed the problem was in PHP, but between the client-side and server-side there could be many things, then always follow the link tips to help people help you– Guilherme Nascimento
I put my javascript codes @Guilhermenascimento. I actually know that the problem is in javascript itself. Sorry I didn’t put the.
– GustavoSevero
This Javascript does nothing :/ only generates the console.log, if I understand the problem you are confusing Ajax and normal upload.
– Guilherme Nascimento
Yes, because I want to see what comes in payload. I want to know if the file is coming.
– GustavoSevero