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.
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.
Pimcore is a leading open source .PHP Pimcore is a powerful and robust Zend Framework based PHP content management system (WCMS) for creating and managing digital content and assets.Innverse Technologies Provides best services in PHP Development services. choose our wide range of package and we create a website for you according your requirement.
ReplyDeleteI am really enjoying reading your well-written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
ReplyDeleteAsp.Net Training in Chennai | Dot Net Training Center in Chennai | Dot Net Coaching Centers in Chennai
Software Testing Institutes in Chennai | Manual Testing Training in Chennai
Java Training Institute in Chennai | Core Java Training in Chennai | Java Course and Certification
PHP Training Institute in Chennai | Best PHP Course in Chennai | Best PHP Training Institutes