-1

I'm trying to upload a file using php. I have a form with input type='file' and I choose the file to upload click to send button.

My HTML code:

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Test Form</title>
</head>

<body>

    <form action="test2.php" method="post" enctype="multipart/form-data">
        <input type="file" name="image1"/>
        <input type="submit" value="send">
    </form>

</body>

My PHP code:

<?php

  move_uploaded_file($_FILES['image1']['tmp_name'],'assets/images/upload/'.$FILES['image1']['name']);

?>

The error in the log file of the apache server is:

PHP Notice: Undefined variable: FILES in ...

Please Could you help me?

ruzD
  • 555
  • 1
  • 15
  • 29

4 Answers4

2

Should be:

<?php

  move_uploaded_file($_FILES['image1']['tmp_name'],'assets/images/upload/'.$_FILES['image1']['name']);

?>
amit
  • 874
  • 7
  • 16
2

you have typo in your code $FILES['image1']['name']

Replace this line

 move_uploaded_file($_FILES['image1']['tmp_name'],'assets/images/upload/'.$FILES['image1']['name']);

with this

move_uploaded_file($_FILES['image1']['tmp_name'],'assets/images/upload/'.$_FILES['image1']['name']);
shubham715
  • 3,324
  • 1
  • 17
  • 27
2
  move_uploaded_file($_FILES['image1']['tmp_name'],'assets/images/upload/'.$_FILES['image1']['name']);

In you move_uploaded_file function you have made the mistake ie the 2nd attribute should be $_FILES Now you please change this then your error will work. Please have a try.

Pranav MS
  • 2,235
  • 2
  • 23
  • 50
0

i think it should be.

<?php

  move_uploaded_file($_FILES['image1']["tmp_name"],'assets/images/upload/'.$FILES['image1']['name']);

?>

tmp_name use as string format.

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34