i'm doing the download file in php.. i've shown all the file in a page and download when user click the download button.. the file name has been stored in an array session within a loop.. when the download button is click, new page downloadfiles.php is open and download the file.. problem is i can only pass the session array value manually.. how can i pass it according to user click on the button?
currently i using $file = $_SESSION['imagefilename'][0]; to manually download the first file in the database.. how can i automatically assign the [0] value based on user click?
display.php
<?php
//pass session email here
$email = $_SESSION['email'];
$image = mysql_query("SELECT * FROM image WHERE email='$email' ");
$numrows = mysql_num_rows($image);
if($numrows!=0)
{
$_SESSION['imagefilename'] = array();
while ($row = mysql_fetch_assoc($image))
{
//get the image path
$path = $row['path'];
//get the image name
$name = $row['name'];
$_SESSION['imagefilename'][] = $name;
$_SESSION['imgpath'] = $path;
echo "<br>Your image: '$name' <br><img src='$path' width='300' height='200'><br><a href='/images/downloadfiles.php' data-role='button' data-theme='e' target='_self' name='download'>Download</a><br><a href='deleteimg.php' data-role='button' data-theme='e' target='_self'>Delete</a></br>";
}
}else
echo "No image found!";
?>
images/downloadfiles.php
<?php
session_start();
// Define the path to file
$file = $_SESSION['imagefilename'][0];
if(!$file)
{
// File doesn't exist, output error
die('File not found');
}
else
{
// Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
// Read the file from disk
readfile($file);
}
?>
i'm doing the download file in php.. i've shown all the file in a page and download when user click the download button.. the file name has been stored in an array session within a loop.. when the download button is click, new page downloadfiles.php is open and download the file.. problem is i can only pass the session array value manually.. how can i pass it according to user click on the button?
currently i using $file = $_SESSION['imagefilename'][0]; to manually download the first file in the database.. how can i automatically assign the [0] value based on user click?