开发者

php how to keep track (in database) of image tag filenames included in html ouput from ckeditor wysiwyg editor

开发者 https://www.devze.com 2023-02-28 22:57 出处:网络
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 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 al开发者_如何学JAVAl 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


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号