Reputation: 5
Marking the question as duplicate is futile, cause I've referred all such questions on SO and none of them did provide a solution.
<?php
if(isset($_POST['submit'])){
$name=$_FILES['filedoc']['name'];
$temp_name=$_FILES['filedoc']['tmp_name'];
if(isset($name)){
if(!empty($name)){
$file=file_get_contents($temp_name);
}
}
else echo"Please upload file";
echo "<form action=\"";echo htmlentities($_SERVER["PHP_SELF"]);echo "\" method=\"post\">
<h2>New Paste</h2>
<label> Upload File? <input type = \"file\" name = \"filedoc\"/></label><br><span class=\"error\">";echo $fileErr;echo"</span><br>
<input id=\"button\"class=\"red\" type =\"submit\" class=\"red\" name=\"submit\" value = \"Paste\"/><br><span class=\"error\">";echo $submitErr;echo "</span>
</form>";
}
?>
Form is being displayed correctly. So there are no errors in the second part. But then, I get this error ( ! ) Notice: Undefined index: filedoc in path of the file
Upvotes: 0
Views: 42
Reputation:
The form also needs the following attribute: enctype="multipart/form-data"
. It specifies which content-type to use when submitting the form
Without the requirement above, the file upload will not work.
Upvotes: 0