I am currently working on a site, of which needs to have it be possible for users to upload an image file. I have the HTML form setup and it seems to be working, this isn't the part with the issue. The issue is the PHP part, where I am getting the file upload, gathering the extension of that file and renaming the file to a specific timestamp and then uploading it into a specific folder.
I have an if
statement to check for the upload, but every time I run the code it returns the "error" statement and when it "echo's" the file name it is missing the extension.
I have tried to run the code through syntax error checkers and nothing returns and when running the code it doesn't show any alerts.
I am not completely sure where the code goes wrong.
Below here is the HTML form
<form action="uploadProdu.php" method="POST" id="productUploadForm">
<input type="file" name="productImage" id="uploadImageFile" class="center-block"><br>
<input type="submit" value="Submit Product" id="submitFormButton">
</form>
Below here is the PHP part
<?php
//This retrieves all the other information from the form
$productImage=($_FILES['productImage']['name']);
//Get the extension of the image uploaded
$imageExtens = pathinfo($productImage, PATHINFO_EXTENSION);
//Generate a timestamp to use and rename the file upload
$ran = round(microtime(true)) ;
//Add a dot to the random number, to then add extension later
$ran2 = $ran.".";
//Subdirectory for image upload (the targeted folder)
$target = "productimages/";
//Combine the folder, the timestamp name and the extension
$target = $target . $ran2 . $imageExtens;
if(move_uploaded_file($_FILES['productImage']['tmp_name'], $target)) {
echo "The file has been uploaded as ".$ran2.$imageExtens;
} else {
echo "Sorry, there was a problem uploading your file.";
echo "The file you tried to upload was called ".$ran2.$imageExtens;
echo "And with directory full length ".$target;
}
?>