Jump to content

whats wrong with this code?


xtreme_dry

Recommended Posts

hey ive got a php file to show the links to all the files in a particular folder but its not working anymore :( can any one help heres the code:

 

this is the include function in my html page

  <?php include("downloadfile.php") ?>

 

and heres downloadfile.php

<html>
<head>
<style>
body {
background-color:#CCCCCC;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
ul {
list-style:none;
}
ul li a {
width:100px;
height:50px;
background-color:#FFFFFF;
border:#000000 1px solid;
text-decoration:none;
color:#000000;
padding:5px;
}
ul li a:hover {
background-color:#CCCCCC
}
</style>
<body>
<?php 

$path  =  "./uploads"; 

$dir_handle  =  @opendir($path)  or  die("Unable  to  open  $path"); 

while  ($file  =  readdir($dir_handle))  { 

if($file  ==  "."  ||  $file  ==  ".."  ||  $file  ==  "index.php"  ) 

continue; 
echo  "<ul><li><a  href=uploads/$file>$file</a></li></ul>"; 

} 

//  Close 
closedir($dir_handle); 

?> 
</body></head></html>

Link to comment
https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/
Share on other sites

lol

 

<?php 

$path  =  "./uploads";

$dir_handle  =  @opendir($path)  or  die("Unable  to  open  $path"); 

while  ($file  =  readdir($dir_handle))  { 

if($file  ==  "."  ||  $file  ==  ".."  ||  $file  ==  "index.php"  ) { 

continue; 
echo  "<ul><li><a  href=uploads/$file>$file</a></li></ul>"; 
}

} 

//  Close 
closedir($dir_handle); 

?> 

 

Maybe?

Try this ok.


<?php 

ob_start();

//path to the file

$path = 'uploads/'; 

//file want to download.

$file='result.php';

echo"<a href='test.php?cmd=page'>Get the page</a>"; 


if($_GET['cmd']=="page"){

$l = "$path$file";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 

header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($l));

header( "Content-Description: File Transfer");
@readfile($l);
}

ob_end_flush();
?> 

You say "this is the include function in my html page". If the name of the file that contains the include statement does not end with ".php", this will not work.

 

I would do a "show source" on the generated HTML and see if there is a problem in the code.

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.