$ _FILES does not work [duplicate]

3

EDIT: Even if you put the ENCTYPE tag on form, the problem persists. I'm trying to use $_FILES for the first time, and I'm experiencing difficulties. It's like he does not get anything. Look at the code I'm using.

HTML:

<form id="formtiles" method="post" enctype="multipart/form-data" action="scripts/cadastro.php" >
    <label for="logo"><b>Logotipo: </b></label>
    <input name="logo" type="file" id="logo" data-mini="true"/>
    <input type="submit" form="formtiles" value="Gravar"  id="enviadadoscliente" data-inline="true" data-icon="check"/>
</form>

PHP:

$location = 'public_html/teste/grid/img';
if (isset($_FILES['logo'])) {
    $name = $_FILES['logo']['name'];
    $tmp_name = $_FILES['logo']['tmp_name'];

    $error = $_FILES['logo']['error'];
    if ($error !== UPLOAD_ERR_OK) {
        echo 'Erro ao fazer o upload:', $error;
    } elseif (move_uploaded_file($tmp_name, $location . $name)) {
        echo 'Uploaded';    
    }
} 

Thank you in advance for the help.

    
asked by anonymous 24.12.2015 / 00:50

1 answer

6

Put in the form tag: entype="multipart/form-data"

EDIT:

Probably the destination folder of the image ( public_html/teste/grid/img ) is wrong, you should access it respecting the example folder hierarchy, your php file is in the folder: public_html/teste/php

Then your path to the img folder should be:

../grid/img/

I am the file php , I am in the folder php , and my path is a folder behind mine, so I have to return a folder (with ../ ) to be able to see the folder grid and consequently img .

Tip:

I suggest using the time() function to generate image names, because if the user uploads two images with the same name an error may occur, change the $name variable to:

$name = time().".jpg";

Sample download link: MEGA NZ

    
24.12.2015 / 01:11