I have gone through countless different help menus and topics for this and still having problems. I simply want to insert the filepath of an uploaded image into a MySQL data
Security issues and deprecated extension aside, all you need to do is insert the file name to the database. To do that, add a "filename" field to your database and then adjust your insert query accordingly:
INSERT INTO products (name, description, price_low, price_high, filename)
VALUES (:name, :desc, :price_low, :price_high, :filename)
Also, your $uploaddir
variable is empty, the files probably aren't even being saved anywhere at the moment. To move your files properly, try something like this:
$uploaddir = '/path/where/you/can/save/';
$rawFilename = $_FILES['userfile']['name'];
$extension = pathinfo($rawFilename, PATHINFO_EXTENSION);
$uploadfile = $uploaddir . md5($rawFilename) . '.' . $extension;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
This script assumes you trust the uploaded content and the md5 function is just is just a quick and easy way to "sanitize" (if I can call it that) the file's name.