Use iframe to indicate a file other than the htdocs folder.
. If you place file.txt in d: \ txt \ file.txt, it cannot be found at http://mydomain.com/file.txt. Use http://mydomain.com/file.php to access File.txt, because file.php is accessible.
Reply to discussion (solution)
Files that are not managed by the web server cannot be accessed through http.
You need to transfer data through the php program
What should I do? My filelist page number can refer to any folder. Can I change it to an embedded file to open it? The page number is as follows:
Error_reporting (0 );
$ Basedir = "c:/filelist ";
If (! Is_dir ($ basedir) $ basedir = dirname (_ FILE __);
$ File_name = $ _ GET ['downfile'];
If (! Empty ($ file_name )){
$ File_dir = $ basedir. "/". $ file_name;
If (dirname (realpath ($ file_dir) <$ basedir ){
Echo "Permission Denied! ";
Exit;
}
If (! File_exists ($ file_dir )){
Echo "File Not Found! ";
Exit;
} Else {
$ File = fopen ($ file_dir, "r ");
Header ("Content-type: application/octet-stream ");
Header ("Accept-Ranges: bytes ");
Header ("Accept-Length:". filesize ($ file_dir ));
Header ("Content-Disposition: attachment; filename =". $ file_name );
Echo fread ($ file, filesize ($ file_dir ));
Fclose ($ file );
Exit;
}
}
Header ("Content-type: text/html; charset = utf-8 ");
$ RequestDir = $ _ GET ['dir'];
If (empty ($ requestDir )){
$ Dir = $ basedir;
} Else {
$ Dir = $ basedir. "/". $ requestDir;
}
$ Dir = realpath ($ dir );
If ($ dir <$ basedir) $ dir = $ basedir;
?>
File Listing
$ Predir = realpath ($ dir ."/../"); If ($ predir> $ basedir) $ predir = str_replace ($ basedir. "/", "", $ predir ); If ($ predir = $ basedir) $ predir = "."; If ($ dir> $ basedir) echo "Up Level "; ?> |
$ Dirs = @ opendir ($ dir ); $ Count = 0; While ($ file = @ readdir ($ dirs )){ $ B = "$ dir/$ file "; $ A = @ is_dir ($ B ); If ($ a = "1 "){ If ($ file! = "..." & $ File! = "."){ If ($ count <1 ){ $ Count ++; Echo"
\ N "; Echo"
Folder | \ N "; Echo"
\ N "; } Echo"
\ N "; Echo"
$ Basedir? Str_replace ($ basedir. "/", '', $ dir."/"):''). urlencode ($ file). "\"> $ file | \ N "; Echo"
\ N "; } } } @ Closedir ($ dirs ); ?>
Filename |
Date |
Size |
Action |
$ Dirs = @ opendir ($ dir ); While ($ file = @ readdir ($ dirs )){ $ B = "$ dir/$ file "; $ A = @ is_dir ($ B ); If ($ a = "0 "){ $ Size = @ filesize ("$ dir/$ file "); $ Size = $ size/1024; $ Size = @ number_format ($ size, 2 ); $ Lastsave = @ date ("Y-n-d H: I: s", filemtime ("$ dir/$ file ")); Echo"
\ N "; Echo"
$ File | \ N "; Echo"
$ Lastsave | \ N "; Echo"
$ Size KB | \ N "; Echo"
$ Basedir? Str_replace ($ basedir. "/", '', $ dir."/"):''). urlencode ($ file). "\"> Download | \ N "; Echo"
\ N "; } } @ Closedir ($ dirs ); ?>
Solved. use the following code.
$ File_handle = fopen ("outsidefile/file.txt", "r ");
While (! Feof ($ file_handle )){
$ Line_of_text = fgets ($ file_handle );
Print $ line_of_text ."
";
}
Fclose ($ file_handle );
?>