How to Upload File in a folder using PHP

How to Upload File in a folder using PHP
  • Select a file using file input type and move it on specific folder mention it on directory Upload file like doc, pdf format with up to specific size.
 
<?php
    if(isset($_POST["SubmitBtn"]))
    {
    //Name of file
    $fileName=$_FILES["resume"]["name"];
    //Size of file In kb 
    $fileSize=$_FILES["resume"]["size"]/1024;
    $fileType=$_FILES["resume"]["type"];//File Type
    $fileTmpName=$_FILES["resume"]["tmp_name"];

    if(($fileType=="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
        ||$fileType=="application/pdf")
        {
        if($fileSize<=200)
            {

            $random=rand(1111,9999);//genrate new file name randmaly
            $newFileName=$random.$fileName;

            //path of uploaded file directory

            $uploadPath="testUpload/".$newFileName;

            if(move_uploaded_file($fileTmpName,$uploadPath))
                {
                echo "Successful<BR>";
                echo "File Name :".$newFileName."<BR>";
                echo "File Size :".$fileSize." kb"."<BR>";
                echo "File Type :".$fileType."<BR>";
                }
            }
        else{
             echo "Maximum upload file size limit is 200 kb";
           }
         } 
   else{
        echo "You can only upload a Word doc file.";
    }

}
?>


<form action="" method="post" enctype="multipart/form-data" name="form1">
    <input type="file" name="resume" id="resume">
    <input type="submit" name="SubmitBtn" id="SubmitBtn" value="Upload Resume">
</form>

16 Replies to “How to Upload File in a folder using PHP”

Leave a Reply

Your email address will not be published. Required fields are marked *