1

I want to make an upload function on my system but there is a message displayed on the webpage even though I did not choose file yet. Can anyone help me? here is my code :

Attachment :

                <td><form action="upload_file.php" method="post" enctype="multipart/form-data">
                <input type="file" name="reservation_Attachment" size="50" />
                <br />
                <input type="submit" value="Upload" />
                </form>

                <?php
                 $targetfolder = "attachment/";
                 $targetfolder = $targetfolder . basename( $_FILES['reservation_Attachment']['name']) ;
                 if(move_uploaded_file($_FILES['reservation_Attachment']['tmp_name'], $targetfolder))
                 {
                 echo "The file ". basename( $_FILES['reservation_Attachment']['name']). " is uploaded";
                 }
                 else {
                 echo "Problem uploading file";
                 }
                 ?>

                 <?php
                 $targetfolder = "attachment/";
                 $targetfolder = $targetfolder . basename( $_FILES['reservation_Attachment']['name']) ;
                 $ok=1;
                $file_type=$_FILES['reservation_Attachment']['type'];
                if ($file_type=="application/pdf" || $file_type=="image/gif" || $file_type=="image/jpeg") {
                 if(move_uploaded_file($_FILES['reservation_Attachment']['tmp_name'], $targetfolder))
                 {
                 echo "The file ". basename( $_FILES['reservation_Attachment']['name']). " is uploaded";
                 }
                 else {
                 echo "Problem uploading file";
                 }
                }
                else {
                 echo "You may only upload PDFs, JPEGs or GIF files.<br>";
                }
                ?></td>
            </tr>

Here are the errors:

Notice: Undefined index: reservation_Attachment in C:\xampp\htdocs\sportvenuereservation\reservation_form.php on line 210

Notice: Undefined index: reservation_Attachment in C:\xampp\htdocs\sportvenuereservation\reservation_form.php on line 211 Problem uploading file Notice: Undefined index: reservation_Attachment in C:\xampp\htdocs\sportvenuereservation\reservation_form.php on line 222

Notice: Undefined index: reservation_Attachment in C:\xampp\htdocs\sportvenuereservation\reservation_form.php on line 224 You may only upload PDFs, JPEGs or GIF files.

Rishav
  • 3,818
  • 1
  • 31
  • 49
  • You need to put all the code that processes the form inputs inside `if ($_SERVER['REQUEST_METHOD'] == 'POST')` – Barmar May 20 '18 at 08:50

0 Answers0