I am new to php, hence cannot figure out my problem. I have an HTML form that is connected to the mentioned php file. This form works fine. The problem is with the php file. The HTML form is:
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
And my php file called upload.php is:
<?php
$uid = $_POST['uid'];
$target_dir = "FILES OF:$uid";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
Here, as you can see in the first lines of the php code, the target directory is set. But I want it to be with a variable called
$uid
which is linked to the uid field in my database meaning username. What I mean to say is that I want it to upload files in the folder called "FILES OF:$uid". I have these folders already created but want a way in which files will go directly to that folder. Does anyone know a way to do this?