Gossamer Forum
Home : Products : DBMan SQL : Discussion :

File Upload

Quote Reply
File Upload
Help Please

Making progress, but when new photo is added it destroys photos in directory - this does not happen when record is modified.

Suggestions please - Using JP Deni mod

Many thanks in advance

Quote Reply
Re: File Upload In reply to
Are you using the short/long display? If so, please check that you have the following lines at the start of both sub html_record & sub html_record_long

my (%rec) = @_;
$rec{$db_key} =~ s/<.?B>//g;




Quote Reply
Re: File Upload In reply to
Thank you very much for your reply

There is no sub html_record_long, but there are
sub html_record_form
and
sub html_record

both include

my (%rec) = @_;
$rec{$db_key} =~ s/<.?B>//g;

There were some discrepencies between the mod code and what we saw in the script. Examples:

db.cfg uses Alpha, we used

Filename => [56, 'BLOB', 0, 255, 0, '', '', 0],
Graphic => [57, 'BLOB', 0, 255, 0, '', 'Yes', 0]

-------------
In db.cgi
we wer unsure about keeping the original, if statement

if (($status eq "ok") && ($in{'Filename'})) { $status = &validate_upload; } #Upload Addition - Validate Picture
if ($status eq "ok") { # Original Line - Keep??

##### UPLOAD
opendir (GRAPHIC, "$SAVE_DIRECTORY") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORY. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
$file_test = $in{$db_key} . ".";
foreach $file (@files) {
if ($file =~ /^$file_test/) {
$in{'Graphic'} = 'Yes';
$graphic_found=1;
}
}
unless ($graphic_found) { $in{'Graphic'} = ''; }


Many thanks again for your kind assistance.

Regards
John

Quote Reply
Re: File Upload In reply to
Hi John, I'm really sorry ... I wouldn't be able to help on the SQL definitions in any way. I know very little about each of them but it seems that I had read somewhere that BLOB was for large text areas. Have you tried changing the cfg file to use alpha instead of blob?


Quote Reply
Re: File Upload In reply to
My apolgies, missed the new question posed in your reply. Yes, you would leave the original if statement. As an example, here is what that area of a cgi file I had tested:

# We keep checking for the next available key, or until we've tried 50 times
# after which we give up.
while ($status eq "duplicate key error" and $db_key_track) {
return "duplicate key error" if ($counter++ > 50);
$in{$db_key}++;
$status = &validate_record;
}
if (($status eq "ok") && ($in{'Filename'})) { $status = &validate_upload; } #Validate Picture

if ($status eq "ok") {
rest of code ...

- - - changed to reflect "file upload" changes instead of the "multi-file upload" changes I had posted.
Quote Reply
Re: File Upload In reply to
Thanks Karen and all that may have an suggestion - fix for this.

Tripled checked all based on the jpdeni mod & recent posts. FYI we are installing this on a Windows machine, and its been confirmed that the scripts will work. Files may be reviewed at http://www.gatman.com/mysql

When we add a record with an upload, it creates a file named: ".gif" or ".jpg" and the next added record with upload does the same thing - so we always have only one file named ".xx"

When we modify any record, then the file / process appears to work and the uploaded file is numerically named "1.jpg", "2.gif", etc.

When we then Add a new record, it destroys the modified uploaded images and reverts to ".xx" again


Data type shouldn't be the problem. MySQL doesn't use Alpha and as I interpret the mod, we are referencing the path to the image and not embedding the binary data in the table. So Blob worked but was probably ineffecient. We also tried CHAR with same results.

Again many thanks for your help.
John

Quote Reply
Re: File Upload In reply to
Aha ... John, there was a scenario such as you've described in your last post which was addressed in a thread in the DBMan Customization forum over the past few months. I hadn't applied the change mentioned there because the sample I had running didn't have the problem.

Try searchng in that forum and I'll have a look too - perhaps we can locate that thread ... might want to check LoisC's unofficial FAQ's too - she is very good about catching problem fixes etc and adding them to her resource site. She may have that thread referenced there.


Quote Reply
Re: File Upload In reply to
John, located the thread - was just last month :-)

http://gossamer-threads.com/p/131774
In Reply To:
What operating system is your site on? Just curious so we can make a note of things - as indicated, your files worked without error on my test environment using FreeBSD.

Okay, I've checked your files and compared with the fix LoisC posted above. Apparently, someone else had problems with the mod and found a fix which worked for them.

In db.cgi, locate this line (about line 368):
$file_test = $in{$db_key} . ".";

and replace with:
$file_test = $rec{$db_key};

For some reason the interaction between your computer and your server is not stripping off the local file path when naming the upload.
Let me know how it goes.


Quote Reply
Re: File Upload In reply to
Thanks Karen

Good tip - Will look for that one!!

Regards
John

Quote Reply
Re: File Upload In reply to
Didn't do it Frown.

Feel we are so close. Appears to be a naming/path issue.

Any other suggestions?