Search This Blog

08 February 2018

UPLOAD FILE USING PHP



UPLOAD FILE USING PHP

Php file  upload  single and multiple file supported  simple codes Php file upload features allows to upload text, binary files  full control over the file to be uploaded through php authentication & file operation functions

Steps :
Form tag add Enctype Attribute Enctype=”multipart/form-data”
Use File Uploaded Function

Move_uploaded_file



MY Directory
    



Upload The File



Coding

<html>
<head><style>.col {
    width: 100%;
    height: 80%;
    magin:0 auto;
}

#s1{
   
    padding: 10px;
border-radius: 6px;
background-color: #4683ea;
width:100px;
color:white;
}

.background-card h4 {

      padding-bottom: 0.5em;

      margin-bottom: 0.5em;

      margin-top: 1em !important;

    }

    h4 > .fa {

      display: none !important;

    }

    .card-nested {

      padding: .5rem 0 .5rem 0;

    }

    .labels {

      display: inline;

    }

    .skill-info {

      margin-left: 0;

    }

    blockquote {

      font-size: 100%;

    }

  }



#s{

  background: radial-gradient(royalblue,skyblue)

}


  #nam{

    background: transparent;

    font-size: 35px;

    font-weight: 800;

    border: none;

    color: #000000;

}

#nm::placeholder{

   color: #000000;

  font-size: 35px;

  font-weight: 700;

}

.form-control:focus {

 background-color: #fff;

 outline: 0;

box-shadow: none;

}

.form-control{

  padding: .375rem 0px;

}





.as::placeholder{

  opacity: 0.2; 

}

#skl{

background: transparent;

font-size: 17px;

border: none;

font-weight: 700;

color: #77b6e9;

}

#skl::placeholder{

color: #000000;

font-size: 17px;

font-weight: 700;

color: #77b6e9;

}

#eml{

  background: transparent;

  font-size: 13px;

  border: none;

  font-weight: 400;

  }

  #eml::placeholder{

  color: #000000;

  font-size: 13px;

  font-weight: 400;

  }

  #pno{

    background: transparent;

    font-size: 12px;

    border: none;

    font-weight: 400;

    }

    .ui-datepicker-calendar {

      display: none;

      }

    #pno::placeholder{

    color: #000000;

    font-size: 12px;

    font-weight: 400;

    }

    



</style></head>
<form method="post" action="" enctype="multipart/form-data">
File<input type="file" name="f1"><br>
<input id="s1" type="submit" name="s" value="upload">
</form><br>
<div class="col">
<ul type="none">
</html>
<?php
$con=mysqli_connect("localhost","root","","test");
if(isset($_POST['s'])){
$fname=$_FILES['f1']['name'];
$dir=$_FILES['f1']['tmp_name']; 

$ext=pathinfo($fname,PATHINFO_EXTENSION);

if($ext=="png" || $ext=="jpg" || $ext=="gif"){

move_uploaded_file($dir,"image/".$fname);
$sql="insert into image values('$fname')";
$con->query($sql);

} else{ 

echo "Your File Type is not Supported only allowed File Types gif,png,jpg";

 }


}
$sql="select * from image order by rand()";
$res=$con->query($sql);
while($row=mysqli_fetch_array($res)){
$img=$row['image'];
?>
<li style="float:left;padding:15px;">
<img height="200" width="300" src="<?php  echo "image/".$img; ?>" alt="img not"></li>&nbsp;
<?php
}
?>

</ul>
</div>

Output:

 



No comments:

Post a Comment

Jquery or Javascript Start Exam Time

 <script> function startTimer() {      var date = "<?php echo $date ?>"; // dynamic date      var time = "<?...