Upload a file using PHP

Pinterest LinkedIn Tumblr

First, write your HTML code like this, and don’t forget to add 

<form action="upload.php" method="post" enctype="multipart/form-data">
  <input type="file" name="fileToUpload" id="fileToUpload">
  <input type="submit" value="Upload Image" name="submit">

Then create a file name called upload.php

$path = "form/";
$target_file =  $path.basename($_FILES["fileToUpload"]["name"]);
$result = move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$target_file.$file);
if ($result) {
    echo "file successfully uploaded";
else {
    echo "please select your file";

Write A Comment