Change Images on update page CMS - php

Well this is the only problem that bugs me a lot every time I create a CMS.
Say I have included the functionality to add some images with text (Not a image gallery) . This is the create function of CRUD. The read and delete are also not very difficult. The only problem I face is with the update function.
How should the image update be handled. How can I know that if the user wants to change the image and later if he submits a new image.
If he checks to change the image and uses the same image to upload, it would be useless to first unlink the previous image and upload the same image again.
How are these kind of things handled?
At this moment I am using codeigniter for Development.

Most CMS's will have image functionality baked in. I'd first suggest not trying to reinvent the wheel here.
In ExpressionEngine for example (on a codeigniter backend) you're givin a 'field tag' <img src="{{channel.img}}" />
The CMS is smart enough on the backend to change that field's value on update without you having to manually do anything. The only issue is if it overwrites the image name/location rather than created a new image in the uploads and leaving the previous one in there.
This is how it's handled in Umbraco CMS as well.
What else do you need?

Related

October CMS - Remove file attachments with unsaved model

I'm trying to create a front-end AJAX file uploader for a form and everything is working perfect, except for one issue.
I used deferred binding to enable uploading before the record is created in DB.
In a rare scenario, when someone uploads a file and doesn't send the form the record is not created, but the attached file still exists.
I don't know if there is a build-in solution for this problem is October CMS.
A better example is RainLab Blog Plugin. If you try a new post and add a featured image but not save the post and close the tab, the post doesn't create but the file remains in storage/app/uploads/public.
I was thinking of writing an scheduled task to delete unbinded files, but don't know how to detect them.
Does anyone have a solution for this issue?
you can look at the table:
system_files
and the ones without a
attachment_id or/and
attachment_type or/and
field
are unused maybe the media table should be cleaned too.

Can I un-cache one image? Or should I do things differently?

I allow users to add a profile picture of themselves to an account, pretty standard stuff.
To make things simple, when they update their image I simply overwrite the image they currently have stored (its not a big part of what we do so simple approach)
So, page is shown with their current image, they can then choose to upload a new one, the uploaded file is then saved, image URL updated in MySQL table and page is displayed again.
The image is uploaded correctly, MySQL table updated correctly, but the image is cached so old image shows on page even though they have uploaded a new one.
Can I un cache one image? Is there a better way to do this?
For avoiding image caching you can simply add a query sting in the image src. Best would be adding a date time.
{$t = getDate();}
and in your image src add: src= "path.jpg?t=".$t
For this you need not to change anything for new image..Date time automatically gets changed every second ;)
Hope it helps..
Use versioning. In the link for the image, instead of abc.jpg say abc.jpg?v=5. And when a new image is uploaded, change the number.
see this question

upload image, then put file path into a form

I just need a bit of advice on what direction to go with something I am creating.
It is a simple php based webpage for our sports and social members in our office, allowing them to create, edit, view and delete events for all members to see. Events like day trips, bbq's and all kinds of things like that.
So far I have it all working as I would like, other than one thing, being the event logos.
At present, the events are all stored in a mysql database, in one table, with a column for every aspect of the event; time, date, price, venue etc etc.
I also have two columns for the event logos, one for the venue logo, and one for the general event logo.
What I need advice on, is the best way to create a page that allows a user to upload an image to the server, browse the images already uploaded, select one, and have it's file path entered into a text input when creating the event.
Could someone offer their suggestions on the best way to go about this, or offer an alternative method for selecting and inputting a logo for the event?
Thanks
The Uploadify jQuery plugin works really well for batch and/or AJAX uploads. The way I'd handle your situation would be this:
Show all images on the same page with the form, and give each image a related radio button with the image path as the button's value, so the user simply checks the image they want to use,
If the user wants to upload images, use the Uploadify plugin and it's AJAX callback functions to dynamically populate the existing list of radio buttons.
The comment I made on your question, asking wether you store images (or their file paths) was because I think it would be much easier (and cleaner) for you to retrieve a list of uploaded images by querying a database. Personally, I don't store images in a database, only their file paths, and use PHP to handle any images that need to be deleted or moved. It's easier to assing images to other entities (especially in many-to-many relationships) that way.
If you don't want to store images' data in a separate table, I guess you'd have to use PHP file system functions to get a list of files already uploaded (glob comes to mind, although there could be better functions or this).
EDIT:
There is also a very good AJAX file browser plugin - ckFinder, but I have very little experience with it and can't really comment on its workflow, but if you find it to be a more elegant solution, you should try it out.
if i could understand your question you want to associate the image with the event i.e tag the image with the event right ??
you can use jquery's attr() function to grab the src of img and put it in input field
I ended up storing the images in the database itself.
Saved some hassle on the file path side of things.

How can I generate a thumbnail of a web page for a facebook post?

My app is posting to users' Facebook walls, and linking to a page they have created. The page is in html. I'd like to be able to put a thumbnail of the page as the image on the wall post. I'm not sure whether this is possible or not. Anyone have any ideas?
If it helps, the page itself is stored as a series of 'elements'... for each one, I know the size and position of the element, and the content (which may be text or an image). So I can pull all that in from the database.
I guess it would be sufficient to create a thumbnail using php at the point when the user clicks 'Publish This to my wall', if that's easier than doing it on the fly - I can save the image and then link to it.
Any ideas?
I create thumbnails for my site using CutyCapt, which works very well indeed on both Windows and Linux. You can use exec to invoke this from php.
There are also web services that allow you a quota of free thumbnail snapshots, that are easy to integrate into your website. e.g.
http://www.websnapr.com/
or
http://webthumb.bluga.net/home
I figured out how to do this. I used the PHP gd library, which allows you to create a base image and then add images and text. Works pretty well.

A good solution for displaying galleries with lytebox and php

I have thought for a while over an issue with the loading of images on a website-solution that I have programmed (For fun and the experience)
The programming language used is PHP with MYSQL as the database language
It also uses javascript, but not extensively
I have recently realized that the engine I programmed, while it has it's smart solutions also carry a lot of flaws and redundant code. I have therefore decided to make a new one, now incorporating what I know, but didn't when I started the previous project.
For the new system, there will be an option to add galleries to a site, and upload images to it. I have used the javascript image viewer Lytebox before. The screen goes dark and an image appears with a "Previous" and "next" button to view the other images.
The problem is that I used groups with lytebox and the images themselves, resized as thumbs. This causes lytebox to work only when all the images have loaded. If you click a link before that, the image is shown as if you right click and choose "Show image"
Information about these images is parsed from a database using a while statement with a counter that goes from 0 to sizeof()
I'm thinking it probably isn't a good idea to have the images as the thumbs, even if you restrict the upload size. Likewise, adding thumbs at upload also seems like a hassle. It would be practical if the thumbs didn't show up before they were fully loaded.
Has anyone got any good tips. Any help would be appreciated.
Johann
Not really. What I would like to know is what route to go when creating a page that lets you upload images. Does other systems usually create thumbs-files when a user uploads a file? Is there a way to display images on the server as thumbs that doesn't require you to load the entire image?
What would also work would be to get lytebox to pop up, with a white frame and "wait" for the image. Basically everything else than opening the image as a regular link.
I had an account here before, seems like it has been reset or something. Tried logging on with both google open-ids. Wouldn't let me comment your comment so I had to do it the hard way and answer my own post :|

Categories