Thursday, October 6, 2016

[Working Code] How to upload a file from client to server using HTML Form and PHP Script

How to upload a file from client to server using HTML Form & PHP Script

Web Technology : File Uploading from Client to Server


HTML Form "sample.html"



<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload File" name="submit">
</form>
</body>
</html>

PHP code "upload.php"


<?php
$target_dir = "uploads/";
$target_file = $target_dir.basename($_FILES["fileToUpload"]["name"]);
if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
           echo "Upload Success";
}
else
{
           echo "Upload Failed";
}
?>

No comments:

Post a Comment