I can’t seem to get the directory to take the user id variable ($id) in the file path. Uploading straight into the member folder is no issue, but once I try for the unique folder created based upon user id during registration, I am roadblocked.
Here is what I’ve pieced together thus far:
<?php
$id = $_SESSION['id'];
$udir= "members/.$id./";
$ufile = $udir . basename($_FILES['file']['name']);
$allexts = array("jpg", "jpeg", "gif", "png");
$ext = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($ext, $allexts)){
if (move_uploaded_file($_FILES['file']['tmp_name'], $ufile)) {
echo "File upload was successful.";
} else {
echo "An error has occured. Please try again.";
}
} else {
echo "Invalid file type. Please try again.";
} ?>
try this
your code:-