How to upload file using php?

Once I had a requirement to upload a file using php.
For that I used following sample code.

 <form name="newad" method="post" enctype="multipart/form-data">
 	<tr><td><input type="file" name="txtUploadFile" id="txtUploadFile"></td></tr>
 	<tr><td><input name="btnSubmit" id="btnSubmit" type="submit" value="Upload image"></td></tr>

  if (isset($_POST['btnSubmit']))
    if ($_FILES["txtUploadFile"]["error"] > 0)
      echo "Error: " . $_FILES["txtUploadFile"]["error"] . "<br />";
	  move_uploaded_file($_FILES["txtUploadFile"]["tmp_name"], "images/" . $_FILES["txtUploadFile"]["name"]);
	  echo "<h1>File Uploaded Successfully.</h1>";

Speak Your Mind

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: