PHP /读取txt文件(或任何东西)

发布于 2024-09-19 07:15:49 字数 405 浏览 5 评论 0原文

我已经搜索了一段时间了,但是像我这样的 php-noob 无法让它工作。

我想要完成的是一种在根目录中创建目录的方法,其中每个目录都包含图像+ txt 文件。假设您已经:

 Root
 |
 +---Directory 1
 |   |
 |   +---Image1.jpg
 |   |
 |   +---Image2.jpg
 |   |
 |   +---Text.txt
 |
 +---Directory 2
     |
     +---Image1.jpg
     |
     +---Image2.jpg
     |
     +---Text.txt

我知道如何读取和显示图像+名称。但是如何显示附带的文本文件呢? (内容是文件的标题,而不是文件的标题)。

非常感谢!

I've been searching for a while now, but php-noob as I am, can't get it to work.

What I'm trying to accomplish is a way to make directories in your root, with in each of them images + a txt file. So let's say you got:

 Root
 |
 +---Directory 1
 |   |
 |   +---Image1.jpg
 |   |
 |   +---Image2.jpg
 |   |
 |   +---Text.txt
 |
 +---Directory 2
     |
     +---Image1.jpg
     |
     +---Image2.jpg
     |
     +---Text.txt

I know how to read and display the images + names. But how do I display the accompanied textfile? (The content that is, not the title of the file).

Much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪痕残 2024-09-26 07:15:49

最简单的方法是使用 file_get_contents ( http://php.net/manual /en/function.file-get-contents.php

echo file_get_contents($path_to_file);

更高级:fopen/fread http://php.net/manual/en/function.fread.php

the easiest way is using file_get_contents ( http://php.net/manual/en/function.file-get-contents.php )

echo file_get_contents($path_to_file);

More advanced: fopen/fread http://php.net/manual/en/function.fread.php

枫林﹌晚霞¤ 2024-09-26 07:15:49

来自 PHP fpassthru 手册:

<?php

// open the file in a binary mode
$name = './img/ok.png';
$fp = fopen($name, 'rb');

// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));

// dump the picture and stop the script
fpassthru($fp);
exit;

?>

From PHP fpassthru manual:

<?php

// open the file in a binary mode
$name = './img/ok.png';
$fp = fopen($name, 'rb');

// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));

// dump the picture and stop the script
fpassthru($fp);
exit;

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文