upload update

1

I have a problem with the way to save the upload file. I have a php file that does the update that is in the folder it processes, and an upload folder to save the files that have been saved.

$id = $_POST['id'];
$titulo = $_POST['titulo'];
$descricao = $_POST['descricao'];
$postador = $_POST['postador'];
$arquivo = $_FILES['arquivo']['name'];

//Substituindo os caracteres especiais
$original = 
'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜüÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿRr"!@#$%&*
()_-+={[}]/?;:,\\'<>°ºª';

$substituir = 
'aaaaaaaceeeeiiiidnoooooouuuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr                                
';

$arquivo = strtr(utf8_decode($arquivo), utf8_decode($original), 
$substituir);

//Substitui os espaços em branco
$arquivo = str_replace(' ', '-', $arquivo);

//Substitui os Maiúsculos por Minúsculos
$arquivo = strtolower($arquivo);

$caminhofinal = "upload".'/'.$arquivo;

move_uploaded_file($_FILES['arquivo']['tmp_name'],$caminhofinal);

$sql_query = "UPDATE posts SET titulo = '$titulo', arquivo = 
'$caminhofinal', descricao = '$descricao', data = NOW(), hora = NOW(), 
postador = '$postador' WHERE id = '$id'";
$resultado = mysqli_query($mysqli, $sql_query);

if($resultado === TRUE){
    $_SESSION['msg'] = "<div class='alert alert-success alert-dismissable'>
                    <a href='#' class='close' data-dismiss='alert' aria-
    label='close'>&times;</a>
                    ID: $id Editado com Sucesso!</div>";

    header("Location: ../professor/lista_conteudo.php");
}  else {
     $_SESSION['msg'] = "<div class='alert alert-danger'>
                    <a href='#' class='close' data-dismiss='alert' aria-
     label='close'>&times;</a>
                    Erro ao Editar ID: $id</div>";
     header("Location: ../professor/editar_conteudo.php");
}

The issue is that you are saving the url in the bank but not the file in the folder. already tried to put in the variable $ finalpath="../upload".'/'.$film; but it did not work. Can someone help me? Thanks!

    
asked by anonymous 09.08.2017 / 16:24

1 answer

-1

As Gabriel Santos commented, the folder options are very important in this case, however for a good understanding of the error it is also important to isolate the possibilities.

When I upload, I isolate this way:

if(move_uploaded_file($arquivo,$destino)){
    //ok
}else{
    //não ok
}

This way you know if the file was sent or not executing the action inside the if check itself.

Now to find out what the problem was, I suggest an approach with try catch:

try {
    if (!move_uploaded_file( ... )) {
        throw new Exception('Arquivo não Enviado!');
    }
} catch (Exception $e) {
    die ('Motivo: ' . $e->getMessage());
}

Hugs!

    
16.08.2017 / 15:16