Upload docx file using PHP script


<html>
<head>
<title>PHP microsoft docx file Upload script</title>
</head>
<body>
<div><?php
if ( isset( $_FILES['docFile'] ) ) {

	if ($_FILES['docFile']['type'] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {

		$source_file = $_FILES['docFile']['tmp_name'];
		$dest_file = "upload/".$_FILES['docFile']['name'];
			

		if (file_exists($dest_file)) {

			print "The file name already exists!!";
		}
		else {

		move_uploaded_file( $source_file, $dest_file )

		or die ("Error!!");


		if($_FILES['docFile']['error'] == 0) {

		print "File was successfully uploaded!! <br/><br/>";
		print "<b><u>Details : </u></b><br/>";
		print "File Name : ".$_FILES['docFile']['name']."<br.>"."<br/>";
		print "File Size : ".$_FILES['docFile']['size']." bytes"."<br/>";
		print "File location : upload/".$_FILES['docFile']['name']."<br/>";

			}
		}

	}
	else {

	if ( $_FILES['docFile']['type'] != "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {

		print "Error occured while uploading file : ".$_FILES['docFile']['name']."<br/>";
		print "Invalid  file extension, should be docx !!"."<br/>";
		print "Error Code : ".$_FILES['docFile']['error']."<br/>";


		}


	}

}
?></div>

<form enctype="multipart/form-data"
	action="<?php print $_SERVER['PHP_SELF']?>" method="post">
<p><input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <input
	type="file" name="docFile" /><br />
<input type="submit" value="upload!" /></p>
</form>
</body>
</html>
Advertisements
Try Out Code2care Dev Tools:

Advertisements



Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency