Advanced HTML Editor Support Product Page

This topic is locked
This topic was archived

Delete Image Before Record

Asked 07 Feb 2004 21:48:41
1
has this question
07 Feb 2004 21:48:41 R M posted:
If I modify or delete the entry, will the images be deleted/modify as well from the server<img src=../images/dmxzone/forum/icon_smile_question.gif border=0 align=middle>

Thanks!

<img src=../images/dmxzone/forum/icon_smile_question.gif border=0 align=middle>

Replies

Replied 07 Feb 2004 22:21:29
07 Feb 2004 22:21:29 George Petrov replied:
This is a very good question. Currently we do not delete the images as well because it is too difficult to check which images are used and which not.

Also you might have copied for example to same html to another record as well - and if the images are trown away then the same images on the other record will be missing.

We are still looking for the best solution for this - if you have ideas let me know.

Greetings,
George

--------------------------------------------------
George Petrov - Founder of the Dynamic Zones
DMXzone.com, FWzone.net, FLzone.net, CFzone.net,
DNzone.com, FlashFreaks.nl
--------------------------------------------------
Replied 09 Feb 2004 16:02:47
09 Feb 2004 16:02:47 R M replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote> if you have ideas let me know.<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Ok, I almost hate you for saying that, because I didn't have any ideas, but then you got me thinking about it and there were my Sunday. All Sunday long thinking about a solution on the back of my mind. Worst of all, I didn't come up with a solution that was easy or practical. In any case, here is a possible solution for the ERASE part of it. And only if the photos are use only one time and photos use this way are in a separated folder from other photos.

I'm assuming the information (A.K.A. ThingyWithPhoto) is going into a SQL dBase. We need to create two additional tables:


TABLE1

NumForCookie INT


TABLE2

NumForCookie INT
ID_ThingyWithPhoto INT
PhotoName nvarchar(400)





STEP ONE

While uploading the photo check if a hidden field on the table has info,named NumForCookie, if not:

/////// If we didn't have the NumForCookie

DECLARE @NumForCookie INT
SET @NumForCookie = (SELECT NumForCookie FROM TABLE1)
SET @NumForCookie + 1

UPDATE TABLE1
SET NumForCookie = @NumForCookie

SELECT @NumForCookie


Insert Into TABLE2 (photoName, NumForCookie)
Values(@photoname, @NumForCookie)

///////


/////// If we had the NumForCookie


Insert Into TABLE2 (photoName, NumForCookie)
Values(@photoname, @NumForCookie)

///////

Take the NumForCookie is put it in, well, a cookie or use a JavaScript to populate a hidden field on the form that has the HTML Editor. The process is repeated for every photo you upload. Of course, after the first photo we already have the NumForCookie, so we just do the upload and the Insert Into TABLE2



STEP TWO

After you submit the form to upload/insert the information (A.K.A. as ThingyWithPhoto), at the same time, you also update information on Table2. You need to get the @@IDENTITY from the table that you inserted the ThingyWithPhoto info.

///////// Script to insert info to ThingyWithPhoto

DECLARE @myIdentity Int

Insert etc etc
SET @myIdentity = (Select @@IDENTITY)

///////

UPDATE TABLE2
SET ID_ThingyWithPhoto = @myIdentity,
WHERE NumForCookie = @NumForCookie

///////

What we did is match all the photos that we previously uploaded with the information uploaded.



STEP THREE

Now when we are going to erase a ThingyWithPhoto we need to not only erase it, but use it's ID number and check which photos it was using with TABLE2.

So its a select with do while that will use FSO do erase each photo from the folder using the photoname and THEN it will delete all records of photos for that THingyWithPhoto from Table2.

Now, for this to work for Update, it would have to delate all photos first and you would have to re-upload the photos that you wanted to keep. <img src=../images/dmxzone/forum/icon_smile_dead.gif border=0 align=middle>

Like I mention before, complicated and none practical... so I'm giving up and leaving it to the great minds of DMX Zone to figure out. <img src=../images/dmxzone/forum/icon_smile_tongue.gif border=0 align=middle>


Replied 09 Feb 2004 22:50:35
09 Feb 2004 22:50:35 George Petrov replied:
Hi IslandTalker!

Now you give me indeed a good subday solution! <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
You are working well in SQL as I can see! Your solution is fine but as you said it yourself - way too complicated ...

You see from the extension writer point of view - I don't really know what database the use have and it is difficult to require that he have some and even create some tables in it...

However your solution push me to think even further so maybe the folowing solution:

* user uploads an image - image is upload to the upload folder and entered in the editor
* user selects an existing image - a new file is created in the same folder where the image was upload with the same name as the image but number appended that describes the number of usage, for example:

if you select image mypicture.gif - the program will look for mypicture_xxx.usg - if there is no such file found mypicture_001.usg will be created. if one is found than only the number will be increased: ie mypicture_002.usg

so the other file will help to determine how often an image has been used - so when the image gets deleted from the editor we can check the reference file and if it does not exist or is 001 - we can savely delete the image. Otherwise just decrease the usage counter.

so something like this ...

I will think further - thanks for your idea! let me know what you think

Greetings,
George

--------------------------------------------------
George Petrov - Founder of the Dynamic Zones
DMXzone.com, FWzone.net, FLzone.net, CFzone.net,
DNzone.com, FlashFreaks.nl
--------------------------------------------------
Replied 10 Feb 2004 06:28:50
10 Feb 2004 06:28:50 R M replied:
Hmm.. yes, close to my idea but simplified. Problem is, besides the number of times it has been use, you need to know WHERE it was been use. So maybe two files, which is similar to the two tables, might work. One with the number of times, and one with the place, otherwise it won't know when it has to delete it or not. There has to be a way to tie the usage of the photo with the photo. Did I just made sense?

But yes, two 'flat' files would be a better idea. But I still think you need a way to get the identity number of the entry from the entry your are doing in the insert or modify. Well, in modify we already have an identity key indentify, otherwise modify wouldn't work.

So one file with the name of the photo and the number of uses, and a second one with the name of the photo and the record is being use at. So when you open or delete that particular record, it erases it knows what photo is need to reduce the number of uses to thru the record identity. Like select photoname where recordID = '1' (It retuns 1234.jpg) Then its deletes the line it just read (where the recordId is at) and updates the first flat file where the number of uses is stored. Hmm.. somewhat simplified. Somewhat being the keyword <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>

[I just read this post and couldn't understand it myself, hope YOU can. :-| maybe I need some sleep]






Edited by - IslandTalker on 10 Feb 2004 06:30:34
Replied 10 Feb 2004 16:50:34
10 Feb 2004 16:50:34 R M replied:
Ok, I think I have an idea, but it would call for some major coding changes on extension, which I'm not even sure if they can be done.

First, when you put the form on a page, you need to choose an upload folder, just like you do with the other upload extensions. Instead of the dBase, we use a Flat File with 3 fields, tab(?) separated:

name of photo
randomNum
IdNum

I think we still need a randomNum, but we can generate that on the fly, instead of getting from a database.

[ Something like this might work:

Dim fs, i, x
Dim strTemp

Set fs = CreateObject("Scripting.FileSystemObject"
strTemp = fs.GetBaseName(fs.GetTempName)
strTemp = Right(strTemp, Len(strTemp) - 3)
Set fs = Nothing
]

There must be a hidden field HTML editor that every time you open a page that has the editor, it gets populated with this random number.

Now, when you click on Image icon and the Insert Image pop ups, there could be a drop down of names of photos that are already on the folder. Either generated by reading the Flat File OR thru FSO reading the actual images on the pre-selected folder.

Lets say you decide to upload one, when you choose and upload the photo the name of the photo and the RandomNum is enter on the Flat File dBase. This happens with every image you upload. If I uploaded 3 images it would look something like this:

foto1.jpg shewe
foto2.jpg shewe
foto3.jpg shewe

Notice that the 3rd field, the IdNum is empty. This is populated ONCE I submit the form, once the form is submitted if must get the Identity and update every line on the Flat File:

foto1.jpg shewe 32
foto2.jpg shewe 32
foto3.jpg shewe 32

This way.. hmm.. wait a minute... maybe you are right, we don’t need all this. o_O

Scrap before for the time being, new idea (keeping previous idea for reference).

Flat file dbase, two fields, photo name and times use.

Keeping this idea: when you click on Image icon and the Insert Image pop ups, there could be a drop down of names of photos that are already on the folder. Either generated by reading the Flat File OR thru FSO reading the actual images on the pre-selected folder.

If you choose an image already on the folder, when you click ok, it updates the Flat File by increasing the number of uses by one.

If you uploaded a new photo, it creates a new entry, photo name and number of uses (1).

Now the trick would be that when you going to modify a photo on the text the editor CAN'T allow you to use the delete key of backspace to delete it. Instead you must select the image by click on it and click the Image icon and then choosing a delete button, so there would be an action and you can update the Flat File updating the number of uses of deleting the entry.

Now could this be possible? I know it could be done if the HTML editor would be a .Net control, is it?

Man, I'm obsessing with this thing. (V)

Replied 16 Feb 2004 15:05:56
16 Feb 2004 15:05:56 Patrick Woldberg replied:
It is a good idea and I also think it is possible, but in code view you can't prevent it from being deleted. But what to do with images pointing to external sites? Also beware that it should work with all languages, we don't want to exclude php.

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Manager at DMXzone.com
--------------------------------------------------
Replied 16 Feb 2004 20:07:02
16 Feb 2004 20:07:02 R M replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>in code view you can't prevent it from being deleted<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

True, but still most people won't use code view. The people that do should be because they know coding to start with. You would have to put a note advising them to use the normal view do delete photos or else they will have to do it manually. It would still be an easier way to manage the photos problem, specially if you use the editor a lot.


<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>what to do with images pointing to external sites<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
If the photos are not in the pre-designated folder for UPLOADED photos, then it would just ignore the Delete Image/FSO part and just delete the code.


<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>Also beware that it should work with all languages, we don't want to exclude php.<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Hmm.. I really don't know PHP, can it do FSO or something similar to it?

Reply to this topic