Rocket
Rocket

Reputation: 1093

HTML File Upload issue

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 ?

Upvotes: 0

Views: 44

Answers (2)

Quentin
Quentin

Reputation: 943615

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">

Upvotes: 1

Leonard Lepadatu
Leonard Lepadatu

Reputation: 646

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

Upvotes: 1

Related Questions