xtreme_dry Posted March 2, 2007 Share Posted March 2, 2007 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 More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 use it like this if($file != "." && $file != ".." && $file != "index.php" ) echo "<ul><li><a href=uploads/$file>$file</a></li></ul>"; [/c0de] Link to comment https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197685 Share on other sites More sharing options...
xtreme_dry Posted March 2, 2007 Author Share Posted March 2, 2007 nope still wont display the files Link to comment https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197694 Share on other sites More sharing options...
xtreme_dry Posted March 2, 2007 Author Share Posted March 2, 2007 is there anything wrong with the include function? because i can open the page fine if i type in the url and it all works it just wont display in the page Link to comment https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197700 Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 try changing $path = "./uploads"; to $path = "uploads"; Link to comment https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197702 Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 you are missing a ; include("downloadfile.php") use this include("downloadfile.php"); Link to comment https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197703 Share on other sites More sharing options...
xtreme_dry Posted March 2, 2007 Author Share Posted March 2, 2007 nope still don't wanna work Link to comment https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197713 Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 windows setting $path = "uploads/"; Link to comment https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197714 Share on other sites More sharing options...
xtreme_dry Posted March 2, 2007 Author Share Posted March 2, 2007 nopes till won't work Link to comment https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197718 Share on other sites More sharing options...
Snooble Posted March 2, 2007 Share Posted March 2, 2007 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 https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197729 Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 try print_r($file); and post here what you get Link to comment https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197735 Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 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 https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197803 Share on other sites More sharing options...
kenrbnsn Posted March 2, 2007 Share Posted March 2, 2007 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 https://forums.phpfreaks.com/topic/40831-whats-wrong-with-this-code/#findComment-197933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.