PHP File upload - Web Development and Web Design Codes

Latest

Friday, April 20, 2018

PHP File upload

how to upload file in php

how to upload file in php
how to upload file in php
Hi Friends in this lesson we are going to learn how to upload file using php..
and display uploaded file from directory..this is very simple script for beginners to learn how to upload file in php..
please use the below codes to create your first php file uploader script..

step 1:
Create 2 files and 1 folder named:
 1. index.php
 2. style.css
and folder name  images
how to upload file in php
Now copy for different files..
1. index.php
index page to show upload form and processing upload selected file..
<?php
//Folder
  $target='images/';
  if(isset($_POST['submit'])){
  $path=$target.basename($_FILES['image']['name']);
  $name=$_FILES['image']['name'];
  $upload=move_uploaded_file($_FILES['image']['tmp_name'],$path);
  if($upload){
      $msg='<img src=images/'.$name.'></img>';
  }else{
	  $msg= 'Image Not Uploaded';
  }
  }
?>
<html>
<head>
<title>PHP Image Upload</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<div id="form">
<h2>Upload Image using PHP</h2>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="image"/>
<input type="submit" name="submit" value="Upload"/>
</form>
<div id="image">
<?php 
if(isset($msg)){
	echo $msg;
}
?>
</div>
</div>
</html>

2. style.css
style to style our index page..
#form{
 width:700px;
 background:#42f48c;
 padding:5px 8px;
 border-radius:5px;
 margin:auto;
 overflow:hidden;
}
input[type=file]{
 padding:5px 0px 5px 5px;
 background:black;
 border-radius:5px;
}
input[type=submit]{
 background:black;
 color:white;
 padding:6px 8px;
 font-weight:bold;
 cursor:pointer;
 border-radius:5px;
}

#image img {
	padding: 3px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
	border: 1px solid #FFFFFF;
	border-radius: 50%; 
	margin-top:0px;
	float:left;
	width:350px;
	height:400px;
}

That's it Friends how to upload file in php..if you like this post please share with your friends..Thank you..

No comments:

Post a Comment

Thank You for Your Comment

Note: Only a member of this blog may post a comment.