存储班级文件的练习

发布于 2024-12-08 21:15:26 字数 260 浏览 1 评论 0原文

如何存储要在类中使用的文件。

例如类文件本身,然后是该类中使用的图像。或者您不在类中使用图像,而只是将输出返回到主页,而主页又使用图像?

最近,我一直在决定是将类使用的图像放在网站的全局目录中还是创建自己的目录中。这让我震惊,因为我意识到用于图像操作或数据库操作的类可以与其他项目一起使用,并且在迁移它们时可能很难尝试在全局文件夹中找到相关图像。

那么如何存储课程中使用的图像呢?或者你不会从类中返回打印输出?

本例中使用的编程语言是PHP。

How do you store files that are to be used in a class.

For example the class file itself, then images used in that class. Or do you not use images in the class, but just return an output to the main page which in turn uses the images?

Recently I have been problems deciding whether to put the images used by a class in the global directory for the website or to create its own directory. This has just stricken me as I realised that a class such as for image manipulation or db manipulation can be used with other projects and it might be hard to try and find the related images in the global folder when migrating them.

So how do you store the images used in your classes? Or do you not return a printed output ever from a class?

The programming language used in this case is PHP.

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

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

发布评论

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

评论(2

眉目亦如画i 2024-12-15 21:15:26

图像存储在单独的文件夹中。首先,图像必须由客户端(浏览器)访问,而 php 文件(除了几个实际在 url 中使用的文件)可以保留在文档文件夹之外。

图像和其他文件的确切路径存储在配置中。这只是一个保存设置列表的小型 PHP 文件。您不应该在类中硬编码图像文件夹的路径。

Images are stored in a separate folder. For one, images must be reached by the client (browser), while the php files (except for a couple that are actually used in urls) can be kept outside the document folder.

The exact path of images and others files is stored in a configuration. This is just a small PHP file that keeps a list of settings. You should not hardcode the path to your images folder in your classes.

怀里藏娇 2024-12-15 21:15:26

这是我使用的结构

/includes
  All the clases that you have
/logs
  Log files
/public_html 
  All the pages visible to the user
  /css
  /javascript
  /images

你可以有一个 config.php 文件,其中有类似这样的东西

define("LIB_PATH", '/includes/');
define("IMG_PATH", '/public_html/images/');

等。

这给你带来了以简短、简单和易于理解的方式使用绝对路径的好处

this is the structure I use

/includes
  All the clases that you have
/logs
  Log files
/public_html 
  All the pages visible to the user
  /css
  /javascript
  /images

You can have a config.php file where you have something like this

define("LIB_PATH", '/includes/');
define("IMG_PATH", '/public_html/images/');

etc.

That gives you the benefit of using absolute paths in a short, simple and understandable way

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