Click here to Skip to main content
15,610,690 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:

  1  <html lang="en">
  2    <head>
  3      <link rel="stylesheet" href="style.css">
  4      <title>Files Upload and Download</title>
  5    </head>
  6    <body>
  7      <div class="container">
  8        <div class="row">
  9          <form action="index.php" method="post" enctype="multipart/form-data" >
 10            <h3>Upload File</h3>
 11            <input type="file" name="myfile"> <br>
 12            <button type="submit" name="save">upload</button>
 13          </form>
 14        </div>
 15      </div>
 16  	<table>
 17  <thead>
 18      <th>ID</th>
 19      <th>Filename</th>
 20      <th>size (in mb)</th>
 21      <th>Downloads</th>
 22      <th>Action</th>
 23  </thead>
 24  <tbody>
 27  <?php
 29  $id=$row['id'];
 30  $name=$row['name'];
 31  $size=$row['size'];
 32  $downloads=$row['downloads'];
 35   $arr = array('id', 'name', 'size', 'downloads');
 36  foreach ($files as &$file) {
 37      $file = $file * 1;
 38  }
 40  ?>
 46      <tr>
 47        <td><?php echo $file['id']; ?></td>
 48        <td><?php echo $file['name']; ?></td>
 49        <td><?php echo floor($file['size'] / 1000) . ' KB'; ?></td>
 50        <td><?php echo $file['downloads']; ?></td>
 51        <td><a href="downloads.php?file_id=<?php echo $file['id'] ?>">Download</a></td>
 52      </tr>
 55  </tbody>
 56  </table>
 57    </body>
 58  </html>

What I have tried:

have tried to put
<?php endforeach;?>
but i still get the same problem
Updated 14-Feb-21 5:23am

1 solution

Notice: undefined variable: row in C:\wamp64\www\johnsite\downloadfile\index1.php on line 31, can you help me to solve this problem?

Short answer: No, we can't.
You have

For us, $row comes from nowhere. Only you can track you app, where is it supposed to come from ? how is it defined ?
We can't answer those questions.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

phpdbg | php debugger[^]
Debugging techniques for PHP programmers[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900