Permission problem when trying to insert an image in a PHP directory

Asked

Viewed 466 times

0

I’m having trouble uploading an image to a directory, it seems I don’t have write permission. I’ve already added chmod 775 for the briefcase and nothing, which could be?

I have my insert file this way:

<html>
<head>
   <title>Teste de upload</title>
</head>
<body>
   <form action="#" method="POST" enctype="multipart/form-data">
      <input type="file" name="fileUpload">
      <input type="submit" value="Enviar">
   </form>
</body>
</html>

<?php
   if(isset($_FILES['fileUpload']))
   {
      date_default_timezone_set("Brazil/East"); //Definindo timezone padrão

      $ext = strtolower(substr($_FILES['fileUpload']['name'],-4)); //Pegando extensão do arquivo
      $new_name = date("Y.m.d-H.i.s") . $ext; //Definindo um novo nome para o arquivo
      $dir = './'; //Diretório para uploads

      move_uploaded_file($_FILES['fileUpload']['tmp_name'], $dir.$new_name); //Fazer upload do arquivo
   }
?>

The mistakes that are happening are these: Erro

2 answers

1

The folders need to contain write permission from the WEB server, you probably did not give such permissions.

Even if you have given 755 the apache user is probably not in the group folder, then put the _www group into that folder.

By the way I believe you are using the MAC, so open your terminal (command+space write term and enter).

After that run the two below commands in the terminal to give the necessary permissions in the folder.

sudo chown andremartins:_www /Users/andremartins/developer/workspaces -R
sudo chmod 755 /Users/andremartins/developer/workspaces -R

Stackoverflow English Answer: https://stackoverflow.com/questions/2001881/correct-owner-group-permissions-for-apache-2-site-files-folders-under-mac-os-x

1


What was happening was that the directory was not being found, so I changed the following section in the code:

move_uploaded_file($_FILES['fileUpload']['tmp_name'], "../uploaded/".$new_name); 

Browser other questions tagged

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