File upload via PHP does not work, no error returned (localhost, XAMPP, Ubuntu)

Asked

Viewed 718 times

-3

I’m following a tutorial on Youtube

I intend to use this upload system later in conjunction with the basic system I am creating for personal use.

I did exactly what the tutorial says except for being using the PDO connection template* .

By choosing the file and clicking send simply I go back to my page without any error, without any file and without anything in the database.

Follow my code for analysis:

<?php

        include('database.php');

        // Create connection
        $conn = mysqli_connect($servername, $username, $password, $dbname);

        // Check connection
        if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
        }

        $msg = false;

        if(isset($_FILES['arquivo'])){
        $extensao = strtolower(substr($_FILES['arquivo']['name'], -4));
        $novo_nome = md5(time()).$extensao;
        $diretorio = "upload/";

        move_uploaded_file($_FILES['arquivo']['tmp_name'], $diretorio.$novo_nome);

        $sql = "INSERT INTO arquivo (codigo, arquivo, data) VALUES (null, '$novo_nome', NOW() )";

        if (mysqli_query($conn, $sql))
             $msg = "Arquivo upado com sucesso.";
            else 
             $msg = "Erro ao upar arquivo" . mysqli_error($conn);}


?>
<h1> Upload de Arquivos </h1>
<?php if($msg != false) echo "<p> $msg </p>"; ?>

<form action="upload.php" method="POST" enctype="multipart/form-data">
    <input type="file" required nome="arquivo"  />
    <input type="submit" value="Enviar" />
</form>

I put it in Pastebin because here it was going wrong, outside the block I’m not yet expert around here

Does anyone know what happens?

Screenshot imagem do upload]

Thanks so much for all your help

  • It might be some configuration in your php conf. Try to force errors to show in the return php. gives a look at this link http://forum.imasters.com.br/topic/369899-resolvidoforcar-o-php-a-showos-bugs/ am not php expert, but always solves my problems seeing the errors returned by php.

2 answers

0


It must be because of that line here:

<input type=\"file\" required nome="arquivo"  />

Voce has to exchange for:

<input type="file" required name="arquivo"  />

and if it is already known that there may be problems with the term "required" in some browser that treat this word differently.

I have not tested, try there!!!

hope it helps

  • It was a lack of attention mistake, damn it! Strange that it did not give nenhha message, I did and it worked however I’m having file permission issues now.

  • Warning: move_uploaded_file(upload/dbe81673fc18c70b469f913c82638192.jpg): failed to open stream: Permission denied in /opt/lampp/htdocs/tutorial-upload/upload.php on line 31 Warning: move_uploaded_file(): Unable to move '/opt/lampp/temp/phpkK1qaS' to 'upload/dbe81673fc18c70b469f913c82638192.jpg' in /opt/lampp/htdocs/tutorial-upload/upload.php on line 31

  • I gave a chmod in Ubuntu to 777 in the upload folder, but I think this is not ideal, some suggestion?

  • which distro you use?

  • Ubuntu 16.04, the upload is only working with. chmod 777 until hj I can’t handle these permissions well.

  • man, unfortunately I use Scientific linux, I have adapted better with the RHEL platform, in mine, gave this problem and I had to set the folder to the apache group of my httpd, besides other necessary permissions, different for Ubuntu (debian).

Show 1 more comment

0

Input is wrong. Not name="file" but name="file"

<input type="file" required name="arquivo"  />
  • It was exactly iso thank you

Browser other questions tagged

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