Lesson 12 PHP file download Script

BOOKC, this time share about Lesson 12 PHP file download Script
File download in PHP is quite easy we have to just scan our directory from which we want to download files
this procedure could be understand more easily by this example;

here we assume that the folder(directory) we want to download file is uploaded_files/ ,


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>File download in PHP</title>
</head>

<body>
<h1>PHP file download.</h1>
<table cellpadding="5" cellspacing="5">
<thead><th>File</th><th>Download</th></thead>
<?php
$path = "uploaded_files/"; // the path for the folder.
if (file_exists($path))
 {
    $files = scandir($path);
for($i=2; $i<sizeof($files); $i++)
{
  ?>
  <tr><td><?php echo $files[$i] ?></td><td><a href="<?php echo $path.$files[$i]; ?>"><img src="dl.gif" /></a></td></tr>
  <?php
 }
}
?>
</table>
</body>
</html>
This script simply output a table with file name and download image.

Bookc
Admin

Hopefully the information we provide can be useful.

Related Article

Press ESC to close