存储班级文件的练习
如何存储要在类中使用的文件。
例如类文件本身,然后是该类中使用的图像。或者您不在类中使用图像,而只是将输出返回到主页,而主页又使用图像?
最近,我一直在决定是将类使用的图像放在网站的全局目录中还是创建自己的目录中。这让我震惊,因为我意识到用于图像操作或数据库操作的类可以与其他项目一起使用,并且在迁移它们时可能很难尝试在全局文件夹中找到相关图像。
那么如何存储课程中使用的图像呢?或者你不会从类中返回打印输出?
本例中使用的编程语言是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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
图像存储在单独的文件夹中。首先,图像必须由客户端(浏览器)访问,而 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.
这是我使用的结构
你可以有一个 config.php 文件,其中有类似这样的东西
等。
这给你带来了以简短、简单和易于理解的方式使用绝对路径的好处
this is the structure I use
You can have a config.php file where you have something like this
etc.
That gives you the benefit of using absolute paths in a short, simple and understandable way