Permission error when renaming file via PHP

Asked

Viewed 41 times

0

$dir = "arquivo/"; 

$file = $_FILES["csv1"];

//Move o arquivo da pasta temporaria de upload para a pasta de destino

if (move_uploaded_file($file["tmp_name"], "$dir/".$file["name"])) { 
    rename($file["name"], "novonome.csv");  
    echo "Arquivo enviado com sucesso!"; 
} 
else { 
    echo "Erro, o arquivo não pode ser enviado."; 
}           

Error:

Warning: Rename(dados.csv,novonome.csv): Permission denied in /var/www/html/importador_de_csv/file.php on line 11

I have tried to give permission to the folder and the file, I just need to rename it after changing it from folder

  • Read this manual will help you. https://php.net/rename

  • Use the path to the file, not just the name: rename($file["tmp_name"], "$dir/novonome.csv")

  • you can already pass its new name inside the function 'move_uploaded_file' example: move_uploaded_file($file["tmp_name"], "$dir/". $novonome)

No answers

Browser other questions tagged

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