PHP / MySql Image Upload
In PHP, users can upload files to the server in easy way. To upload files, the PHP script used with an HTML form. Initially, files are uploaded into a temporary directory and then moved to a target destination by a PHP script.
Information in the phpinfo.php page depicts the temporary directory that is used for the process of file uploads as upload_tmp_dir and the utmost allowed size of files that can be uploaded is declared as upload_max_filesize. These parameters are placed into the php.ini PHP configuration file.
The procedure of uploading a file follows these steps -
- The user opens the page containing an HTML form featuring a browse button, text files and a submit button.
- The user presses the browse button and picks a file to upload from the local computer.
- The complete path to the picked file appears in the text field, then the user presses the submit button.
- The chosen file is sent to the temporary directory on the server.
- The PHP script that was stated as the form handler in the form's action feature checks that the file has arrived and then copies the file into an intended directory.
- The PHP script confirms the victory to the user.
As usual, when writing files, it is essential for both the temporary and final locations to have consents set that allow the file writing. If either is fixed to be read-only then the process will be unsuccessful.
An uploaded file could be an image file or text file or any document.
// time() use for generate the unique name for image
$sql="insert into posts set image1='$g1'";
// upload is folder name, where your image will save
alert("Your Image Uploaded Successfully.");
<form method="post" action="" enctype="multipart/form-data"> <input type="file" name="image1" placeholder="upload image here" > <br><br> <input type="submit" name="submit"> </form>
Waiting for your comments