uploading single file in php

To upload a single file, the following code is useful. NOTE: you just need to fix the path of $uploaddir

<!doctype html>
<meta charset="utf-8">
<title>Untitled Document</title>



if( isset($_POST['btnsubmit']) )

$uploaddir = 'A:/AAA/www/web/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) 
    echo "File is valid, and was successfully uploaded.\n";
    echo "File upload failed!\n";

<form action="" method="post" enctype="multipart/form-data" name="form1">
  <input type="file" name="userfile" id="userfile"> <br>
  <input id="btnsubmit" name="btnsubmit" type="submit" value="Upload">


Add a Comment

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