I have the following code to save the uploaded file to a static directory.
<?php
//set the image size in mb
$max_upload_size='10';
$MAXIMUM_FILESIZE = $max_upload_size * 1024 * 1024;
$uploaddir = './uploads/file/';
$file = $uploaddir . basename($_FILES['uploadfile']['name']);
if ($_FILES['uploadfile']['size']<$MAXIMUM_FILESIZE) {
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
echo "success";
} else {
echo "error";
}
}else{
echo"size_error";
}
?>
But what I want is to create a username directory under “/uploads/file/”. For example if the username is “john”, then it should create a folder like “/uploads/file/john/” and saved the file under that folder.
Note – User needs to be logged in to work
Reference –
wp_mkdir_p()
–