I've spent most of my day working on this image uploader, after browsing and visitng many many threads and forums I've found several solutions to my problems however I am now at the point where if I try a different solution, something else breaks.
What I've got so far:
<form action="create.php" method="post" enctype="multipart/form-data">
Select File
<input type="file" name="upload">
<input type="submit" name="submit" value="Upload" />
<input type="text" name="title" placeholder="Title" />
<input type="text" name="description" placeholder="Description" />
<input type="text" name="category" placeholder="Category" />
</form>
<?php
$conn = new PDO ("mysql:host=localhost;dbname=project;", "root", "0612733771Aa");
Full PHP is here, couldnt figure the formatting
The main error I'm getting is this:
if (isset($_POST["submit"]) && isset($_FILES['upload'])) {
$image_size = getimagesize($_FILES['upload']['tmp_name']);
if ($image_size === FALSE) {
die("Unable to determine image type of uploaded file");
}
Warning: getimagesize(): Filename cannot be empty in C:\Apache24\htdocs\create.php on line 29 Unable to determine image type of uploaded file
Any help would be much appreciated!
You need to call at the end of php file after all the image validations
if (move_uploaded_file($image, $any_custom_target_file_path)) {
echo "The file has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
After this you can save the $any_custom_target_file_path in the database. As once the script is executed, tmp file will get deleted so we need to save this to some location.