0

possibly a stupid question but how do I upload files to a server using the browser ?

I'm sure I've used this before ! But when I run it nothing appears to happen.

No errors are shown and nothing is logged in the error_log

<?php
var_dump($_FILES);
echo $_FILES['uploadFile']['tmp_name'];

?>

<html>
<head>
<title>File Upload Form</title>
</head>

<body>
This form allows you to upload a file to the server.<br>
<form action="test.php" method="post"><br>

Type (or select) Filename: <input type="file" name="uploadFile">
<input type="submit" value="Upload File">
</form>


</body>
</html>

What am I doing wrong ?

2 Answers 2

1

When you submit a form, the data you are sending to be encoded somehow to be put in the HTTP request.

By default, this uses the application/x-www-form-urlencoded algorithm which does not support file uploads. You need to use multipart/form-data instead.

<form action="test.php" method="post" enctype="multipart/form-data">
Sign up to request clarification or add additional context in comments.

1 Comment

Both answers were the same.. I picked this as it was the first answer. Thanks
1

Try to correct you form declaration attribute and always when you need to upload files include "enctype". If not file input element is in form, the default enctype is "application/x-www-form-urlencoded":

<form action="test.php" method="post" enctype="multipart/form-data">

FORM in HTML

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.