I need to retrieve form values to insert.php file in order to store them in the database. However one of the elements in the form is a file chooser dialog to upload an image file in JPG or other file format.
I found this code online to send the image via a post request, but cannot get it to work correctly
$pic=($_FILES['photo'][image']);
It only displays the name of the file and not the actual file itself
First of all you need to add the
enctypeattribute to your HTML form. Like this:Next, when this will be sent on the next page use the
$_FILESglobal array instead of the$_POSTarray to retrieve the image.All text data will be sent using
$_POSTbut the file will be transferred using$_FILES.Edit: If you further want to insert this uploaded data in the table (although this is never recommended and is a huge performance loss)
Note: Here I am considering
/var/wwwas my web folder which is configured as default localhost on Linux machines.