0
Error you are showing when I execute the code:
Warning: move_uploaded_file(fotos/7d80310d2fa83125d395d77e6f739bb8.png): failed to open stream: Permission denied in /var/www/PHP/Diego/Funcoes_PHP/upload_imagem/upload.php on line 15 Warning: move_uploaded_file(): Unable to move '/tmp/phpvi9j6k' to 'fotos/7d80310d2fa83125d395d77e6f739bb8.png' in /var/www/PHP/Diego/Funcoes_PHP/upload_imagem/upload.php on line 15 erro
The code I’m using is just below:
<?php
include ("conexao.php");
$msg = false;
if(isset($_FILES['arquivo'])){
$extensao = strtolower(substr($_FILES['arquivo']['name'], -4));
$novo_nome = md5(time()).$extensao;
$diretorio = 'fotos/'; //diretório para o upload
/move_uploaded_file(filename, destination)
if(move_uploaded_file($_FILES['arquivo']['tmp_name'], $diretorio.$novo_nome)){
echo 'Arquivo salvo com sucesso em : <strong>' . $diretorio . '</strong><br />';
echo ' < img src = "' . $novo_nome . '" />';
}else{
echo 'erro';
}
$sql_code = "INSERT INTO arquivo (codigo, arquivo, data) values (null, '$novo_nome', NOW())"; //função now() pega o horário atual
mysql_query($sql_code,$conexao) or die (mysql_error(""));
}
?>
<?php if($msg!= false) echo "<p> $msg </p>";?>
<h1>Upload</h1>
<form action="upload.php" method="POST" enctype="multipart/form-data" >
Arquivo: <input type="file" required name="arquivo">
<input type="submit" value="Salvar">
</form>
Confirmed syntax error: https://www.php.net/manual/en/function.move-uploaded-file.php
– Maury Developer
Diego, why create two identical questions?
– Woss