php 如何跟踪(在数据库中)包含在 ckeditor wysiwyg 编辑器的 html 输出中的图像标签文件名

发布于 2024-11-04 08:01:23 字数 770 浏览 3 评论 0原文

我已经更改了这篇文章的标题,因为我认为我还没有清楚地表达我的问题...... 这是我的第一篇文章,所以请温柔地对待我!

我正在为几年前为客户构建的一个小型静态站点构建内容管理系统。

客户渴望在网站的某些内容区域中能够以博客式的方式自由输入格式化文本和图像。我选择了 ckeditor 和 ckfinder 来完成这些任务。

对于网站的所有其他部分,我可以毫无问题地设想如何上传/输入这些数据并将其存储在数据库中,并提供给模板的每个实例等。我的困难在于构思如何在 PHP 中提取图像发布数据时所见即所得字段内容的文件名。

我会在 $_POST['wysiwygText'] 上使用 regex() 并搜索 wysiwyg 编辑器输出的 html 中的任何 .jpg/.png/.gif 等 - 如果是这样,我会使用什么函数/搜索参数?

我只是想这样做,因为网站的其余图像名称将存储在数据库中,其中域规则更加严格,例如,每个菜单的标题和文本中都会有 1,2 或 2 个设置大小的图像总是以相同的方式格式化...-理论上,存储网站每个页面上使用的图像记录是一种很好的做法吗?我只是认为随着客户端添加和取出图像以在不使用时自动删除图像等会更容易。

但是我可以预见,如果在所见即所得区域内使用图像名称,那么跟踪多对多关系可能真的很困难在不同页面上使用图像,因为将此逻辑添加到 ckeditor 的输出中是一项不合理的任务。或者我应该对我的客户更加坚定,没有所见即所得编辑器,而是使用简单的表单字段来在文本字段中输入图像 - 如果所见即所得选项被认为是不可管理的,那么一些代码的示例将非常好。

非常感谢您的任何贡献/帮助/建议

I have changed the title to this post as I think I have not been clear with my question...
This is my first post, so please be gentle with me!

I am building a content management system for a small static site which I built for a client some years ago.

The client is eager within some content areas of the site to be able to enter formatted text and images freely - in blog-esque fashion. I've chosen ckeditor and ckfinder for these tasks.

For all other parts of the site I've no problem envisaging how this data would be uploaded/entered and stored in a database and served to each instance of template etc. My difficulty is in conceiving how I would - in PHP - extract the image filenames from the wysiwyg field content when posting data.

Would I use regex() on the $_POST['wysiwygText'] and search the html outputed by the wysiwyg editor for any .jpg/.png/.gif etc - if so what function/search argument would I use?

I'm only trying to do this as the rest of the site's image names would be stored in a db where the domain rules are more ridig eg, every menu will have either 1,2 or 2 set sized images in it's header - and text is always formated the same way...- theoretically is is good practice to store a record of images used on each page for a site? I just thought it would easier in time as client adds and takes out images to have images automatically removed when not used etc.

However I can forsee that if image names used within the wysiwyg area it might be really difficult to track many to many relationships of images used on different pages as it would be an unreasonalbe task to add this logic to ckeditor's output. Or should I just be firmer with my client and not have wysiwyg editor but simple form fields to input images within a text field - an example of some code to do that would be excellent if the wysiwyg option is deemed to unmageable.

Many thanks for any contributions/help/suggestions

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

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

发布评论

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

评论(1

暗地喜欢 2024-11-11 08:01:24

您可以通过 $_FILES 全局数组访问所需的所有信息,该数组在上传图像时自动为您创建。

http://php.net/manual/en/reserved.variables.files.php

用法示例。注意:这没有错误检查,例如最大文件大小、文件类型等,这只是一个让您走上正确路径的示例。

if ($_FILES)
{
$uploadDir = 'images/';

$filename = $uploadDir . $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $filename);
}

else echo "No image uploaded"

You can access all of the information needed with the $_FILES Global array that is automatically created for you when an image is uploaded.

http://php.net/manual/en/reserved.variables.files.php

Example usage. Note: this has no error checking such as max file size, file type etc etc, It's only an exmaple to get you on the correct path.

if ($_FILES)
{
$uploadDir = 'images/';

$filename = $uploadDir . $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $filename);
}

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