I can’t run a class

Asked

Viewed 34 times

0

So guys, I’m trying to run an app to upload an image to my server. Without saving this data to the database, the upload usually occurs, but when trying to include the image link in the database, php simply does not perform, as if it had Alum code error. I have already reviewed these Phps and my javascript several times, but I do not find any error. I made the script by watching a video lesson and in class everything works perfectly, but when I apply it to my server it doesn’t work: it follows 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);

connects.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;
            }
        }

1 answer

0


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.