I want to automatically create a folder, using the users email address, if one does not already exists. This action should occur when they upload a file.
SOLVED. I updated this code for anyone who might need it. Thanks!
Here is my code:
if(isset($_POST["checkFile"]) && $_FILES["selectFile"]["name"] != "") {
$target_path_pdf = "uploads/pdfs/$email/";
if ( ! is_dir($target_path_pdf)) {
mkdir($target_path_pdf);
}
$target_path_pdf = $target_path_pdf . str_replace(' ', '_', basename($_FILES["selectFile"]["name"]));
if(move_uploaded_file($_FILES["selectFile"]["tmp_name"], $target_path_pdf)) {
}
else {
$flag = 1;
}
$pdfcaption = $_POST['pdfCaption1'];
}
if(isset($_POST["checkPicture"]) && $_FILES["selectPicture"]["name"] != "") {
$target_path_pic = "uploads/pictures/$email/";
if ( ! is_dir($target_path_pic)) {
mkdir($target_path_pic);
}
$target_path_pic = $target_path_pic . str_replace(' ', '_', basename($_FILES["selectPicture"]["name"]));
if(move_uploaded_file($_FILES["selectPicture"]["tmp_name"], $target_path_pic)) {
}
else {
$flag = 1;
}
$piccaption = $_POST['picCaption1'];
}
This might not be super secure, but that’s a different problem.
For the first part:
http://php.net/manual/en/function.mkdir.php
EDIT
Even though it might be obvious it can’t hurt to explain.
The script simply checks if the directory already exists, and if it doesn’t it creates one.