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
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?

Link to comment
Share on other sites

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();
?> 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.