PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fernado1283
Forum Newbie
Posts: 22 Joined: Mon Aug 25, 2003 2:00 am
Post
by fernado1283 » Mon Aug 25, 2003 10:20 pm
Hi,
I am new in PHP and i really need help from you. I am trying to retrieve the lastest file from the particular folder and display it into the browser while the rest of the files remain as downloading links for the users. Can anyone please help me with my problems. Thanks.
Regards.
Fernado
Code: Select all
<?php
include("doc_function.inc.php");
htmlheader(); // prints html header
$dir = "./"; // current directory
// Print the directory name as a heading title
$filedir = getcwd(); // get current dir
$dirname = getHeader($filedir);
print "<br>";
print "<font size=+1 face="Times New Roman" color="Blue"><b> ";
print "$dirname </b>";
print "</font> ";
print "<hr>";
getFiles($dir); // displays all the files in the folder
getFooter($dir); // displays the "back" and "home" links
print "</blockquote>
<body>
</html>";
$number_of_records = 0;
$directory = "./";
$directory_listing = array();
recrusive_list_dir_contents($directory);
krsort($directory_listing);
reset($directory_listing);
$i = 0;
while(list($ctime, $file) = each($directory_listing))
{
if($i++ == $number_of_records)
break;
else
$recent_files[$ctime] = $file;
}
Global $recent;
$recent=$file;
echo "Latest file path is $recent";
function recrusive_list_dir_contents($directory)
{
GLOBAL $directory_listing;
if(!is_dir($directory)){
echo "$directory is not a directory";die;
}
if($directory[strlen($directory)-1] != "/")
$directory .= "/";
$dp = opendir($directory);
while (($file = readdir($dp)) !== false){
if($file[0] != "." && $file != "index.php")
{
if(is_dir($directory.$file))
recrusive_list_dir_contents($directory.$file);
else
$directory_listing[filectime($directory.$file)] .= $directory.$file;
}
}
//return 0; // a mere formality
}
$openfile=fopen ($recent ,'r+b' );
?>
?>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Aug 25, 2003 10:55 pm
what exactly is the problem?
fernado1283
Forum Newbie
Posts: 22 Joined: Mon Aug 25, 2003 2:00 am
Post
by fernado1283 » Tue Aug 26, 2003 12:08 am
Hi,
The problem is how am i going to display the information inside the file into the browser.
Fernado
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Aug 26, 2003 12:31 am
ah, ic.
That really depends on the content-type of those files.
might be as simple as
Code: Select all
echo '<div class="filecontent"><pre>';
readfile($filename);
echo '</div>';if it is a text file with trusted content (e.g. no html)
fernado1283
Forum Newbie
Posts: 22 Joined: Mon Aug 25, 2003 2:00 am
Post
by fernado1283 » Tue Aug 26, 2003 12:42 am
Hi,
So if happens the file to be in pdf format???
Fernado
fernado1283
Forum Newbie
Posts: 22 Joined: Mon Aug 25, 2003 2:00 am
Post
by fernado1283 » Tue Aug 26, 2003 12:56 am
Hi,
Actually because all my files are in pdf format, therefore, i could not display the information in the browser. Can you help me how I should do it please. Thanks
Fernado
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Aug 26, 2003 1:24 am
you could let the client handle the output.
Since the <object> approach doesn't seem to work anymore for AcrobatReader you might try something like
Code: Select all
<html>
<head></head>
<body>
<iframe src="test.pdf" style="float: left; width: 500px; height: 600px;"></iframe>
<div style="float: left;">
dummy file list
<ul>
<li>a file</li>
<li>b file</li>
<li>c file</li>
</ul>
</div>
</body>
</html>
fernado1283
Forum Newbie
Posts: 22 Joined: Mon Aug 25, 2003 2:00 am
Post
by fernado1283 » Tue Aug 26, 2003 1:47 am
Hi,
Sorry, the thing dont work. I think is because im working on Mac Safari, cannot use iFrame on top of it. Is there any other methods to display the pdf file. Thanks
Fernado
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Aug 26, 2003 1:56 am
no iframes? o_O
ok, I don't like them as well, but ...
what happens with
Code: Select all
<html>
<head></head>
<body>
<iframe src="anotherExistingHTMLFile.html" style="float: left; width: 500px; height: 600px;">sorry, can't do that</iframe>
<div style="float: left;">
dummy file list
<ul>
<li>a file</li>
<li>b file</li>
<li>c file</li>
</ul>
</div>
</body>
</html>and what if you enter the url of a pdf-file in your browser's navbar?
fernado1283
Forum Newbie
Posts: 22 Joined: Mon Aug 25, 2003 2:00 am
Post
by fernado1283 » Tue Aug 26, 2003 2:23 am
Hi,
Actually I also not sure where the problem lies, because it print out the code instead. This is what i did below.
Code: Select all
<?php
include("doc_function.inc.php");
htmlheader(); // prints html header
$dir = "./"; // current directory
// Print the directory name as a heading title
$filedir = getcwd(); // get current dir
$dirname = getHeader($filedir);
print "<br>";
print "<font size=+1 face="Times New Roman" color="Blue"><b> ";
print "$dirname </b>";
print "</font> ";
print "<hr>";
getFiles($dir); // displays all the files in the folder
print"
< iframe src="$recent" style ="float: left; width: 500px; height: 600px;"></ iframe >
< div style ="float: left;" >
</ div >";
getFooter($dir); // displays the "back" and "home" links
print "</blockquote>
</body>
</html>";
$number_of_records = 0;
$directory = "./";
$directory_listing = array();
recrusive_list_dir_contents($directory);
krsort($directory_listing);
reset($directory_listing);
$i = 0;
while(list($ctime, $file) = each($directory_listing))
{
if($i++ == $number_of_records)
break;
else
$recent_files[$ctime] = $file;
}
Global $recent;
$recent=$file;
echo "Latest file path is $recent";
function recrusive_list_dir_contents($directory)
{
GLOBAL $directory_listing;
if(!is_dir($directory)){
echo "$directory is not a directory";die;
}
if($directory[strlen($directory)-1] != "/")
$directory .= "/";
$dp = opendir($directory);
while (($file = readdir($dp)) !== false){
if($file[0] != "." && $file != "index.php")
{
if(is_dir($directory.$file))
recrusive_list_dir_contents($directory.$file);
else
$directory_listing[filectime($directory.$file)] .= $directory.$file;
}
}
//return 0; // a mere formality
}
?>
?>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Aug 26, 2003 3:23 am
which browser do you use and which program displays pdfs on your system?
fernado1283
Forum Newbie
Posts: 22 Joined: Mon Aug 25, 2003 2:00 am
Post
by fernado1283 » Tue Aug 26, 2003 3:43 am
Hi,
I am working on Mac OS using safari and internet explorer to view
and the program to display is preview only.
Fernado
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Aug 26, 2003 10:08 am
that might be the problem. There is no pdf viewer with a plugin for your browser available? I doubt there isn't.
Of course you might let the server render the pdf to another format but I'd rather save the server's time
fernado1283
Forum Newbie
Posts: 22 Joined: Mon Aug 25, 2003 2:00 am
Post
by fernado1283 » Tue Aug 26, 2003 8:39 pm
Hi,
if now I wanted to open a powerpoint file and display it out, can it be done, if yes, how is it done. Please help me.
Fernado