Try declaring your variable $file
with global scope. It should be undefined because its first use happens inside an if.
Also check that your files are writable in your project directory so they can create directories at runtime. I tested it in Linux and it worked.
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<button type="submit">Enviar</button>
</form>
<?php
$file = "";
if ($_SERVER["REQUEST_METHOD"]==="POST"){
$file = isset($_FILES["file"])?$_FILES["file"]:"";
}
$dir ="upload4";
if(!is_dir($dir)){
mkdir($dir);
echo "Pasra criada com sucesso";
}
if (!empty($file)) {
move_uploaded_file($file["tmp_name"],$dir.DIRECTORY_SEPARATOR.$file["name"]);
}
Also put an if to verify that the $ file variable is empty. This prevents you from having Warning: Illegal string offset 'tmp_name'