Permission problem when trying to insert an image into a directory with PHP

0

I'm having trouble uploading an image to a directory, it seems like I'm not writing permission. I already added chmod 775 to the folder and nothing, what could it be?

I have my insert file like this:

<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 errors that are happening are these:

    
asked by anonymous 25.04.2015 / 20:20

2 answers

1

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

move_uploaded_file($_FILES['fileUpload']['tmp_name'], "../uploaded/".$new_name); 
    
25.04.2015 / 20:27
1

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

Even if you gave 755 the apache user is probably not in the folder group, then put the _www group to this folder.

On the way I believe you are using the MAC, then open your terminal (command + space type term and enter).

Then run the two commands below on the terminal to give the necessary permissions on the folder.

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

Stackoverflow English Answer: link

    
27.04.2015 / 19:09