Im trying to upload an image after i sent a formular in uploads directory and create a subdirectory for every user.After i sent the formular the image i upload isnt move to the folder.
if (isset($_FILES['filename'])) {
if (isset($_FILES["filename"]["tmp_name"]) && $_FILES["filename"]["tmp_name"]) {
$imagename = $_FILES["filename"]["name"];
$check = mime_content_type($_FILES["filename"]["tmp_name"]);
// $imgData = addslashes(file_get_contents($_FILES['filename']['tmp_name']));
// $imageProperties = getimageSize($_FILES['filename']['tmp_name']);
if ($check != 'image/png' && $check != 'image/jpg') {
echo "<script>alert('Format fisier gresit');
window.location.href='programare.php';
</script>";
}
$target_dir = "uploads/" . trim($id, "\"");
if (!file_exists($target_dir)) {
mkdir($target_dir, 0777, true);
}
if (move_uploaded_file(basename($_FILES["filename"]["tmp_name"]), $target_dir)) {
echo "The file has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
var_export($_FILES["filename"]);
}
} else {
echo "<script>alert('Introduceti o poza cu problema');
window.location.href='programare.php';
</script>";
}
}
This is the form code
<label>Imagine: </label><input type="file" id="myFile" name="filename" id="filename">
The subfolder is created but the image isnt uploading subfolder this is shown
UPDATE:
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["filename"]["name"]);
if (!file_exists($target_dir)) {
mkdir($target_dir, 0777, true);
}
if (move_uploaded_file(($_FILES["filename"]["tmp_name"]), $target_file)) {
echo "The file has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
var_export($_FILES["filename"]);
}
this works, it save all the images in the uploads folder, but the logic above, doesnt move the files to new subfolder with the name of userid instead it replace the name of file , if the i upload image.png , it will upload 1image.png for user with id 1.

$target_dirso that the server is able to write to it?$target_file = $target_dir . basename($_FILES["filename"]["name"]);not set to the correct place, how about tryprint_r($target_file);before themove_uploaded_file()to see where its going?