0

I have a simple form

<form method="post" action="editownpage.php" id="uploadForm" enctype="multipart/form-data">

    <label for="file">xxx</label>
    <input type="file" name="file" id="file"> <br>

    <label for="uplCss">xxx.</label>
    <textarea id="uplCss" name="uplCss"> <?php echo $css; ?></textarea> <br>

    <input type="submit" name="uplSubmit" id="uplSubmit" value="Hochladen">
</form>

The textarea field works like a charm, but I want to let the user upload a image. But when I do this var_dump($_FILES['file']); it is always null. No image can be processed ? What can be the reasons ? The max. file size in the php.ini is set to 3mb. The images I'm uploading are 70kb.

Musterknabe
  • 4,781
  • 9
  • 52
  • 101

5 Answers5

3

You're missing your enctype="multipart/form-data" attribute in your <form> tag. Without it the file will not upload.

<form enctype="multipart/form-data" method="post" action="editownpage.php" id="uploadForm">
John Conde
  • 207,509
  • 96
  • 428
  • 469
1

Also your var_dump ( $_FILES['file] ); should be:

var_dump ( $_FILES['file'] );

You are missing off the '

MarkP
  • 2,478
  • 4
  • 29
  • 47
1

You have

var_dump ( $_FILES['file] );

You are missing the closing quote.

Use $_FILES['file'];

Read this documentation about how to access the file properties. it can be helpful for you

PHP File Upload

Bill the Lizard
  • 369,957
  • 201
  • 546
  • 842
Danny22
  • 1,876
  • 2
  • 28
  • 59
0

You're missing your enctype="multipart/form-data" attribute in your form tag

See this example as to why it is important.

What does enctype='multipart/form-data' mean?

Community
  • 1
  • 1
MarkP
  • 2,478
  • 4
  • 29
  • 47
0

Try this without giving the index name. Its working at my side.

echo '<pre>';
var_dump($_FILES);
echo '</pre>';

or use.

echo $_FILES['file']['name'].'<br />';
echo $_FILES['file']['type'].'<br />';
echo $_FILES['file']['size'].'<br />';
Sid Ch
  • 21
  • 3