I can not execute a class

0

So folks, I'm trying to run an application to upload an image to my server. Without saving this data in the database, uploading normally occurs, but when trying to include the image link in the database, php simply does not execute, as if it had an error code. I have already reviewed these PHPs and my javascript several times, but I do not find any errors. I did the script by watching a video lesson and in class everything works perfectly, but when I apply it on my server it does not work: follow the codes:

javascript:

<script src="js/upload.min.js"></script> 
    <script>
    $('#i_ver').click(function(){ //avança para div de upload
        $('#inicia_verificacao').fadeOut(600);
        $('#doc_frente').fadeIn(600);
    });
    $('#id_frente').change(function(){ //ao selecionar imagem, envia o formulario
        $('#uploadfile').ajaxForm({
			url: 'php/conecta/docupload.php',
			type: 'post',
            beforeSend: function(){
                $('#loading').show();//mensagem de loading
            },
			success: function(data){
                $('#loading').hide();//esconde loading
				alert(data);//mostra resposta do servidor
			}
		}).submit();
    });
    </script>

docupload.php:

            include_once 'conecta.php';
            session_start();

            $cpf = $_SESSION['cpf'];
            $cpfformatado = str_replace(array('.', '-'), "", $cpf);

            $pasta = "../../uploads/".basename($cpfformatado);
            $arquivo = $pasta."/".basename($_FILES['frente']['name']);

            if (!is_dir($pasta)) {
                mkdir($pasta, 0755, true);
            }
            if (move_uploaded_file($_FILES['frente']['tmp_name'], $arquivo)) {
                $conn = new conecta();
                $conn->uploadDocumento($_FILES['frente']['name'], $arquivo, $cpf);

                $saida = array(
                    "success" => true,
                    "link" => str_replace('../..','',$arquivo)
                );
            }
            else{
                $saida = array(
                    "success" => false,
                    "erro" => 'Imagens não enviada'
                );
            }

            echo json_encode($saida);

connect.php:

        include_once 'config.php';
        class conecta extends config{
            var $pdo;
            public function __construct(){
                $this->pdo = new PDO('mysql:host='.$this->host.';dbname='.$this->db, $this->user, $this->pass);
            }


            public function getDocumento($cpf){
                $sobe = $this->pdo->prepare("SELECT link FROM documentos WHERE cpf = :cpf");
                $run = $sobe->execute();
                $clayton = array();
                while($rs = $sobe->fetch(PDO::FETCH_ASSOC)){
                    array_push($clayton,$rs['link']);
                }
                return $clayton;
            }


            public function deleteDocumento($foto, $cpf){
                $acao = $this->pdo->prepare('DELETE FROM documentos WHERE link = :foto AND cpf = :cpf');
                $acao->bindValue(':foto',$foto);
                $acao->bindValue(':cpf',$cpf);
                $run = $acao->execute();
            }


            public function uploadDocumento($nome, $foto, $cpf){
                $acao = $this->pdo->prepare('INSERT INTO documentos (id, nome, link, cpf) VALUES (NULL, :nome, :foto, :cpf)');
                $acao->bindValue(':nome',$nome);
                $acao->bindValue(':foto',$foto);
                $acao->bindValue(':cpf',$cpf);
                $acao->execute();

                $resposta = array(
                    'success' => true
                );

                return $resposta;
            }
        }
    
asked by anonymous 30.01.2018 / 16:07

1 answer

0

After searching a lot and redoing the code several times, I discovered that to call the class and execute functions with "external" parameters, it is necessary to char the file with "requeire_once". so the answer is there if someone has a similar problem.

    
31.01.2018 / 00:48