cakephp 查找多个图像并显示它们(可能在 webroot 之外?)
我目前正在尝试构建一个 cakephp 应用程序,它将列出数据库中的项目,并且数据库中有一个名为图片的字段。该图片字段包含一个作为主图片的字符串,例如 ABCD,然后在图像文件夹中这是 ABCD.jpg
但是,该特定项目通常有各种额外的图片,可能被命名为 ABCD1 或 ABCD_2 或其他名称这种变化的后缀。我之前在 php 中编写了一些脚本,它使用 glob 函数并对文件进行计数并输出它们。
我正在认真努力地在 cakephp 中执行此操作,目前在 /images 中服务器的 webroot 中存储了数千个图像,并且我知道 cake 将在应用程序的 webroot 中查找,例如 /app/webroot,所以是可以查看他们原来的位置吗?或者必须移动它们...
我已经阅读了一些有关文件和文件夹类的内容,但我正在努力理解它们,不确定我的大脑是否在这里失败了,或者这实际上是一个困难的概念..
我的问题是如何通过项目 ID 选择后,我在图片字段中找到任何以此前缀开头的文件,然后显示与该特定项目匹配的所有文件?
感谢您的帮助!
I am currently trying to build a cakephp app that will list items from a database, and there is a field in the database named picture. This picture field contains a string which is the primary picture, so for example ABCD, and then in the images folder this is ABCD.jpg
However there is usually various extra pictures for this particular item, which may be named ABCD1 or ABCD_2 or some other such variating suffix. I had previously written some script in php which used a glob function and counted the files and outputted them.
I am seriously struggling to do this in cakephp, at the moment there is several thousand images stored in the webroot of the server in /images and I understand that cake will be looking in the webroot of the app like /app/webroot, so is it possible to view their original location? or must they be moved...
I have read a little about the file and folder classes but I am struggling to comprehend them, not sure if my brains failed me here or if this is actually a difficult concept..
my question is how would I find any files that begin with this prefix in the picture field after selecting by the id of the item, to then display all those that match for that particular item?
thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是您问题的真正答案,但您应该开始与您的照片建立数据库关系。
查看
hasMany
在您的之间建立关系文章
(或其他任何内容)和图片
模型。现在您不必查找每个文件名,因为您的数据库中已有它。Not a real answer to your question but you should start making a database relationship with your pics.
Check out
hasMany
to make a relationship between yourArticle
(or whatever it is) and thePicture
models. Now you will not have to look for each filename, as you'll have it in your database.