-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
PLEASE HELP, we are trying to upload images to our site using html and php but its not working.
We have
<form action="add_item.php" id="newItem" method="POST" enctype="multipart/form-data">
and
<input type="file" id="image_file" name="image_file" accept="image/*" required>
and also in add_item.php:
$image_path = "";
if (isset($_FILES['image_file']) && $_FILES['image_file']['error'] == UPLOAD_ERR_OK) {
$targetDir = "public/images/";
if (!is_dir($targetDir)) {
mkdir($targetDir, 0777, true);
}
$fileName = basename($_FILES['image_file']['name']);
$targetFilePath = $targetDir . $fileName;
if (move_uploaded_file($_FILES['image_file']['tmp_name'], $targetFilePath)) {
$image_path = "./public/images/" . $fileName;
} else {
$image_path = ""; // Upload failed, you might want to handle this case differently
}
} else {
// No file was uploaded or an error occurred
$image_path = "./public/images/default.png";
}but no file is uploading, and also, the path is not getting grabbed from file name
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels