I am using code for an to upload files as seen below:
$uploaddir = "./images/";
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.
";
} else {
echo "Upload failed";
}
The code works to upload the image but I want to be able to post the filename to an SQL database afterwords.
I need to get the filename I uploaded and make it a variable called $filename
so i can then use:
$image = $_POST[$filename];
I've tried using this to make it a variable
$filename = $_FILES['userfile']['name'];
All I get is an error saying undefined index : image.jpg on the $_POST
and I'm uncertain why. Its listing the image filename in the error so why cant it upload it.