0
<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’ve tried going to the terminal and executing 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 the XAMPP.
The error persists because, even if you have changed the directory permissions, you are trying to change the code again (and it is the code that has no permissions to make this change). Try to replace the code part
if (!chmod($pasta, 0755))
forif (!is_writable($pasta))
.– Woss
worked thanks
– Manuel Jose