<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
Selecione : <input name="arquivo" type="file">
<input type="submit" value="Enviar">
</form>
<?php
//Salva a foto com nome aleatório dentro da pasta
$pasta = 'pasta-upload';
$arq = $pasta . '/' . uniqid(rand(), true);
$image = false;
if (!chmod($pasta, 0755)) {
echo 'Erro ao mudar as permissões';
} else if (isset($_FILES['arquivo']['tmp_name'])) {
if ($_FILES['arquivo']['error'] !== UPLOAD_ERR_OK) {
echo 'Erro no upload';
} else {
$tmp = $_FILES['arquivo']['tmp_name'];
$image = getimagesize($tmp);
$ext = str_replace(array('image/', 'x-'), '', $image['mime']);
$arq .= '.' . $ext;
if (!$image) {
echo 'Formato invalido';
} else if (!move_uploaded_file($tmp, $arq)) {
echo 'Erro ao mover o arquivo';
} else {
echo '<img src="', $arq, '">';
}
}
}
?>
</body>
</html>
Returns the following
Warning: chmod (): Operation not permitted in /Applications/XAMPP/xamppfiles/htdocs/tm/index.php on line 16 Error while changing permissions.
I have tried to go to the terminal and execute the commands
sudo chmod 777 /Applications/XAMPP/xamppfiles/htdocs/tm/pasta-upload
cd /Applications/XAMPP/xamppfiles/htdocs/tm/
sudo chmod 755 /Applications/XAMPP/xamppfiles/htdocs/tm/pasta-upload
I'm using XAMPP.