This tutorial demosntrate how to upload image without database using PHP and store uploaded image into folder directory. with php it’s easy to upload any images that you want to the browser, you can upload jpeg, png, gif etc. a php script can be used with a HTML form to allow users to upload files to the server. Initially files are uploaded into a directory and then relocated to a target destination by a php script. The php script that was specified as the form handler in the forms action attribute checks that the files has arrived and the copies the files into and intended directory. uploading image is a common feature in today’s PHP projects. you will first have to understand basics of file uploading in PHP. in this post we will go through the basics of PHP file uploading .
How to upload image without database using PHP
Information in the phpinfo.php page describes the temporary directory that is used for file upload as upload_tmp_dir and the maximum permitted size of files that can be uploaded is started as upload_max_filesize . and you may also increase upload max file size . these parameters are set into PHP configuration file php.ini
Creating a upload Form using HTML
The following HTML source code below create a uploader form this form is having method attributes set to post and enctype attributes is set to multipart/form-data .
<form action="upload_image.php" method="post" enctype="multipart/form-data">
Select Image:<input type="file" name="image"><br /><br />
Description:<input type="text" name="desc"><br /><br />
<input type="submit" name="upload" value="Upload Now">
Creating Image upload Script using PHP
in this step we are creating a image upload script using php. there is one global php varriable $_FILES . this varriable is an associate double dimension array and keeps all the information related to uploaded files. if the value assigned to the input’s name attributes in upload form was file then php would create following varriables .
$_FILES [‘file’][‘name’] – The original name of the file on the client machine.
$_FILES [‘file’][‘size’] – The size , in bytes, of the uploaded file.
$_FILES [‘file’][‘type’] – The mime type of the file, if the browser provided this information. an example would be “image/gif” . This mime type is however not checked on the PHP side and therefore don’t take its value for granted.
$_FILES [‘file’][‘tmp_name’] – The temporary filename of the file in which the uploaded file was stored on the server.
$image_name = $_FILES['image']['name'];
$image_type = $_FILES['image']['type'];
$image_size = $_FILES['image']['size'];
$desc = $_POST['desc'];
echo "<img src='photos/$image_name' width='400' height='250'><br>$desc";
If you facing any type of problem with this source code then you can Download the Complete source code in zip Formate by clicking the below button Download Now otherwise you can send Comment.