PHP does not upload image to Azure

Asked

Viewed 20 times

0

Problem: When the user selected the desired image and tries to save it, it cannot move inside the server.

I’ve tried so many ways but the same mistake always happens.

HTML:

<form action="php/NEmpresa.php" method="POST" enctype="multipart/form-data">
                <h1>Empresa</h1>
                <div class="NEmp1">
                    <div class="AEFoto" onclick="document.getElementById('NEphoto').click();">
                        <img id="previewImage" class="AEFoto1">
                        <input type="file" name="NEphoto" id="NEphoto" style="display: none;" onchange="document.getElementById('previewImage').src = window.URL.createObjectURL(this.files[0]);">                        
                        <div class="AEFoto2">
                            <img src="img/foto.png" class="AEFoto2-1">
                        </div>
                    </div>
                    <input type="text" name="donoempresa" placeholder="Dono da Empresa">
                </div>
                <div class="NEmp2">
                    <div class="NEmp3">
                        <input type="text" name="nomeempresa" placeholder="Nome da Empresa">
                        <button>Guardar</button>
                        <div class="close2" onclick="fecharpop2()">
                            <img src="img/popup-close2.png">
                        </div>
                    </div>
                    <div class="NEmp4">
                        <input type="text" name="descricao" placeholder="Descrição">
                    </div>
                </div>
            </form>

Php:

if( isset($_FILES['NEphoto']['name']) ){

                                $utilizador = basename($_FILES['NEphoto']['name']);  
                                $dir = "Imagens/".$utilizador.".png";

                                if( move_uploaded_file($_FILES['NEphoto']['tmp_name'], $dir) ){
                                        
                                        $stmt = sqlsrv_query($conn,"SELECT * FROM fotos WHERE utilizador = '$utilizador';");
                                        if(sqlsrv_fetch($stmt) == 0){
                                                $stmt = sqlsrv_query($conn,"INSERT INTO fotos (imagem) VALUES ('$dir');");
                                                sqlsrv_fetch($stmt);
                                        }

                                        $response['error'] = false; 

                                }else {

                                        $response['error'] = true; 
                                        $response['message'] = "Something Went Wrong Please Retry"; 

                                }  
                        }else{

                                $response['error'] = true; 
                                $response['message'] = "Error"; 

                        }
No answers

Browser other questions tagged

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