Gossamer Forum
Home : Products : DBMan : Customization :

uid password and image deletes

Quote Reply
uid password and image deletes
Hi Guys,

I have two questions please.

I want to use the $db_uid for image path purposes, but need to get rid of the password. How do I strip the password from the variable $db_uid?

I would also like to delete the image files that the image fields point to, when the record is deleted. There are up to 4 images.

Can anyone help??

Thanks in advance
Greg

Quote Reply
Re: uid password and image deletes In reply to
$db_uid does not include the password. It includes a humungous random number. If you want to just use the userid, use the variable $db_userid.

As for deleting the image files, a few questions first. How are the files named? (I know they use the userid, but, since there can be up to 4 files, there must be more to the name.) Do all the image files have the same extension? Are all the image files in the same directory? Is that directory on the same server as the DBMan script?


------------------
JPD







[This message has been edited by JPDeni (edited September 28, 1999).]
Quote Reply
Re: uid password and image deletes In reply to
Hi Carol,

Where you find the time I will never know, but I am thankful you do Smile

I have created a dir called dbimages within the web dir for a domain. Using the $db_userid you just mentioned (thank you) I plan to create directories named after the userid and the images they upload will be stored in these directories with the first two characters being the record ID to make it unique. Expample:

./html_dir/dbimages/userid/IDimage1.jpg
./html_dir/dbimages/userid/IDimage1_small.jpg
./html_dir/dbimages/userid/IDimage2.jpg
./html_dir/dbimages/userid/IDimage2_small.jpg

The images .._smalls are obviously thumbnails

I am not using your upload mod (more than 1 image), but going to allow password access to selected clients for both dbman edits and FTP. The FTP makes the upload quite easy, but the delete of a record, might be a bit difficult to maintain once the images grow to a large number. General users will obviously be able to view records.

You can check the first phase out at:

http://www.choicenet.co.za/cgi-bin/dbman/choice/db.cgi

The only records I have are under the town knysna.

The output is not perfect as it is frame based, but I have'nt completed this yet

If you want I can send you the admin data so you can see exatly how it's laid out.

Appreciate the time.
Thanks and regards
Greg



Quote Reply
Re: uid password and image deletes In reply to
So each user might have more than one record?

Let me think about this one a bit. I'll have to play around a little with reading directories and accessing the filenames.

Would the user be the only one to be deleting records? I can envision a problem if the admin deletes the record, because the userid won't be as readily available.

Where do I find the time? I don't really. I just try to squeeze extra minutes when I can. If anybody knows where I can purchase another 3 or 4 hours a day, please let me know. Smile


------------------
JPD





Quote Reply
Re: uid password and image deletes In reply to
Hi Carol,

The time fdifference is reason for delay in gettiong back to you. Gotta eat & sleep unfortunately. It drags me away from dbman. I fight, but it wins every time. Then there is my wife, kids ... Smile.

Yes, each user and it will only be selected users, will be able to store multiple images and records. Default users will only be able to view.

mmmm I see what you mean about the admin. Essentially I am admin so I could only use this for user administration. It should not be necessary for admin to delete records anyway. Each user is going to maintain their own records. After sending the last message I had to re-think the dir structure. A comment you made me reconsider the dir layout.

I want to create a common db for Real Estate agents. The records will contain essential data about a property, farm, business etc. for sale. Records could have up to 4 fields that is essentially a path to the image and thubmnails. The image dir will reside in a common html dir.

.html/$Agency/$Town/$userid/$Category/$IDimage.jpg or gif

The agency is company name. Town is area and category will be farm, business, vacant land etc. The $userid and unique ID make sure the dir and image is unique. I will setup FTP access for each $userid so that they can only store images in their own directories. I will also rig the html.pl to include a display of the record with a confirm button before adding, which hopefully will limit them getting the image name wrong.

Users browsing then will be able to view properties either within the web site of the Estate Agent or from a global page which lists all properties by all Estate Agents. Each property on the global site displays a clickable URL linked Co. logo plus contact info for the agent concerned.

Within each Agency site only the property info is displayed with contact details.

Hope this is clearer???
If this cannot be done via dbman. I will have to suffer the image deletes via FTP

Much obliged for the continued assistance.

regards
Greg


Quote Reply
Re: uid password and image deletes In reply to
I understand about sleeping and family. Smile We all have to work around our own time zone and life outside of DBMan. (What?!?! A life outside DBMan?!?!?! Wink )

I'm really glad that you included the full information about the directory structure. What I first had in mind won't work with the structure you have. That's the bad news. The good news is that you, as admin, would be able to delete the files, too.

A couple of other, little structural questions and we can get this thing going.
Are $Agency, $Town, $userid, $Category, and $ID all values in record fields? If so, are these the exact names of the fields?

You mentioned $IDimage. Does that mean that, if I had added a record with the ID of 1234, that my image would be named 1234image.gif?



------------------
JPD





Quote Reply
Re: uid password and image deletes In reply to
>Are $Agency, $Town, $userid, $Category, and >$ID all values in record fields? If so, are >these the exact names of the fields?

Yes EXCEPT userid which is the dbman generated $db_userid

>You mentioned $IDimage. Does that mean >that, if I had added a record with the ID >of 1234, that my image would be named >1234image.gif?

Yes, but its a manual entry at the time of addition.

The user at the time of addition will note the ID field number and manually enter the image names as the appropriate ID plus image names into the image fields. He then must FTP/upload the images with the unique names. The ftp access will route him to the proper dir. All he will do is select the dir of category and upload.

Does this makes sense??
If there is an easier way it would be great, but I suspect it would mean a major rewrite of the cgi.

Thanks & regards
Greg
Quote Reply
Re: uid password and image deletes In reply to
It would be a major rewrite of the cgi to do it all automatically. (The mind boggles! Smile

This is going to take me a little while to do and I haven't even read most of the other questions since yesterday yet. I promise I'll get back to you.



------------------
JPD





Quote Reply
Re: uid password and image deletes In reply to
I think I've got it. Be *sure* to backup all your files before you try this, though. Smile

In db.cgi, sub delete_records, change

Code:
$delete_list{$data[$db_key_pos]} ? # if this id is one we want to delete
($delete_list{$data[$db_key_pos]} = 0) : # then mark it deleted and don't print it to the new database.
($output .= $line . "\n"); # otherwise print it.

to

Code:
if ($delete_list{$data[$db_key_pos]}) {
$path = "/path/to/directory";
$delete_list{$data[$db_key_pos]} = 0;
%rec = &array_to_hash(0,@data);
$directory = "$path/$rec{'Agency'}/$rec{'Town'}/$data[$auth_user_field]/$rec{'Category'}";
opendir (DIRECTORY, "$directory")
or &cgierr("unable to open directory in delete_records: $directory. Reason: $!");
@files = readdir(DIRECTORY);
close DIRECTORY;

foreach $file (@files) {
if ($file =~ /^$rec{'ID'}/) {
unlink ("$directory/$file")
}
}
}
else {
$output .= $line . "\n";
}

Be sure you set the $path variable to the full path to the main directory where your image files are. No trailing slash!!

It is set up so that an admin can delete the files, too, since it uses the userid from the record.


------------------
JPD







[This message has been edited by JPDeni (edited September 29, 1999).]
Quote Reply
Re: uid password and image deletes In reply to
Hi Carol,

Wow that was quick. When you said wait I thought you meant a couple of days Smile.
I will give it a bash and let you know.
Thanks very much.

Regards
greg
Quote Reply
Re: uid password and image deletes In reply to
Hello again,

No not at all, but if I include the variable $db_userid in the path when a default user logs in the path becomes:

$path/$Agency?/$Town/default/$Category.. etc
which is not valid.

I have therefore removed $db_userid so that the path now is:

$path/$Agency/$Town/$Category/Image...

This works Ok as default users should be able to view ALL records. The users with password access are for edit purposes only. This means that Estate Agents can manage their own listings(records). Default users can view or search for listings in any town Category, price range within all the Estate Agent listings. I have it all working except for the image deletes.

Hope this helps. Thanks for the continued assistance.
Greg



Quote Reply
Re: uid password and image deletes In reply to
Hi Carol,

Sorry for delay, but I'm involved in a different crisis at the moment.

I tried the mod and it goes thru the motions of delete, but the images remain. Are there not dir permissions or attributes that need to be set?

I have not been able to debug anything yet, but I did discover that the $db_userid is not feasible as default user then results in an incorrect path to the images. I have removed the $db_userid from the path and have decided this will still be OK.

I looked thru your code and it seems sound and I cannot see any reason why it should not work. I will build a dummy cgi with just your code plus set variables and try it out. This ought to do the trick. If you have any bright ideas in the meantime please let me have them.

Thanks & regards
Greg

Quote Reply
Re: uid password and image deletes In reply to
Yes, you do need to have the directory and file permissions set at 666, but that would have to be at the time the file was uploaded.

Quote:
the $db_userid is not feasible as default user then results in an incorrect path to the images.

Are you allowing default users to delete records?



------------------
JPD





Quote Reply
Re: uid password and image deletes In reply to
I understand now.

The problem with image deletes is almost assuredly based on permissions. When a user uploads a file through FTP, the file "belongs" to the user who uploaded it -- whatever username was used for the FTP. The normal permissions for the file are 644, which means that the user can read and write to the file, but everyone else can just read it.

When the script is run, the user is "nobody." In order for "nobody" to be able to delete the file "he" must have write permission. To allow the "nobody" to have write permission on a file uploaded by somebody else, the permission for the file must be 666.

(I learned about this with the file-upload mod. Without the files having their permissions set to 666 at the time of uploading, I couldn't delete the file from my own webspace by FTP. I had to delete them through the script.)


------------------
JPD





Quote Reply
Re: uid password and image deletes In reply to
Set the dir mode to 777 and it works like a charm. Carol you are an absolute gem.
I will mail you to check out the finished page. I must setup quite a lot of ftp accounts and other html.pl files for the various agents.

Thanks very much for your valuable input.
Greg

Quote Reply
Re: uid password and image deletes In reply to
Hi carol,

Me again. Back with the image deletes. The mod you gave works well except if I have more than 10 images. I think you are deleting all files with the first character postition equal to the ID which is essentially correct, but when there are more than 10 images I end up deleteing record 11 12 13 14 etc. if I want to delete record 1. I can overcome this by starting the ID at 1000, which essentially means that I will need to get to 999 images before I start the problem. If I ever get to 999 images per agency per category it will be a miracle.

Ok so the problem is. Can I and if so how do I get to delete all files in the appropriate dir when the Id filed is 4 characters in length? Is it a change to:

$delete_list{$data[$db_key_pos]} = 0;

in the mod.

Thanks again Smile.
G
Quote Reply
Re: uid password and image deletes In reply to
You could do that, but I don't think that's what you want.

Can you give me some specific filenames that you would have, with the id, any text that comes after it and what extensions they would be? I think we can make this a little neater, but I need to know what I'm dealing with.


------------------
JPD





Quote Reply
Re: uid password and image deletes In reply to
Hi Carol,

Ok back from 3 hours kip.

I can actually give the image names anything I want really. I want to make it as easy for the user as possible. Real Estate Agents aren't the most computer literate people around in SA. I have created the dir structure path/$Agency/$Town/$Category to make it easy for the user more than aything else. In order to make the file name unique, as we might get up to 5000 images I thought it best to link it to the ID. I started the ID's at 1000 thinking it would be make sense to delete 1000*.jpg in the appropriate dir and also to avoid what I previously thought was happening.

So the file names (1 large and 1 thumbnail) for ID 1 would be as follows:

1000RF3252.jpg
1000RF3252_small.jpg

Id 2 would be something like

1001RK2771.jpg
1001RK2771_small.jpg

It is possible that an image could be gif, but it would be very scarce. I need to keep this possibility open as I am hoping to adapt the cgi for other products.

I hope this makes sense.
Tks very much
G
Quote Reply
Re: uid password and image deletes In reply to
You know, on second thought, I don't think there's a problem at all, except that you do need to use a 4- or 5-digit ID number.

The line

if ($file =~ /^$rec{'ID'}/) {

just looks to see if the filename begins with the same characters as the value of $rec{'ID'}. It doesn't matter how many characters there are.

The line

$delete_list{$data[$db_key_pos]} = 0;

just is a flag to keep track of the records that have been deleted.

Yes, you are correct that, if you delete all files that are named 1*, you will delete 12*, 105*, 10746*, etc.



------------------
JPD





Quote Reply
Re: uid password and image deletes In reply to
Hi Carol,

Please accept my most humble apologies for harping on this issue again :-).

I have a possible 4 image entries plus 4 thumbnails. Your mod correctly deletes the files in the selected directory. As an example.

1001a.jpg
1001b_small.jpg
1001b.jpg
1001b_small.jpg
1001c.jpg
1001c_small.jpg
1001d.jpg
1001d_small.jpg
are correctly deleted leaving all other files intact, provided they do not start with 1001.

My problem is that each addition increments the counter file. The counter file is not decremented with each deletion. With multiple towns and agencies we could reach 9999 quite quickly, creating a potential double deletion problem. I could use 5 or even 6 digits as an ID, but I am concerned that all we are doing is delaying the problem. Given that the image names are associated with the ID I forsee a major maintenance nightmare if and when the limits are reached.

I was wondering how difficult it would be to actually extract the image names from the record and delete the actual file name. The field names are:

Image1 Image1t
Image2 Image2t
Image3 Image2t
Image4 Image4t

Your assistance would be greatly appreciated.

Tks &rgds
G