Gossamer Forum
Home : Products : DBMan : Installation :

File upload...

(Page 2 of 3)
> > > >
Quote Reply
Re: File upload... In reply to
Why can't you? Because in order to save the file you have to specify the path to the directory. If your directory is on another site, you don't have the correct path to work with.

You could put the file-upload script on the other site, though, and upload files that way.



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





Quote Reply
Re: File upload... In reply to
The only thing I have to do is copy the script to the cgi-dir on the other site, chmod it and change the form-action-path in both sub's 'add_succes' and 'modify_record_form' in the html.pl???

Another question for make this complete for me:
How can I give a field a value of the 'URL of the picture', only when a picture is added??
Quote Reply
Re: File upload... In reply to
 
Code:
foreach $extension (@extensions) {
(-e "$SAVE_DIRECTORY/$data[$db_key_pos].$extension") && (unlink "$SAVE_DIRECTORY/$data[$db_key_pos].$extension")
}
,must there an ';' at the end of '(unlink "$SAVE_DIRECTORY/$data[$db_key_pos].$extension")'??
I've tried it but without any results.
Thanks in advance.
Greetings,
----
Mart.

Quote Reply
Re: File upload... In reply to
The graphic is still there, not deleted, also not with you last code. The record was deleted. What would I do, There must be a way to delete the graphics at the same time as the records.
Quote Reply
Re: File upload... In reply to
JPD, Got it work now!!! Smile Smile
Its just the notation of the 'unlink' operation, the command must between '<..>' and not between '".."' (got it out of my 'Perl-book'), also the '$data' has to change in '$values' I think that was it.

Thank you for your great help.
Only one thing for this topic:

How can I fill a field, depending whether a graphic is uploaded, I have a field reserved for this. I think there must be something in the 'upload_succes' sub, but I really don't know ...
Quote Reply
Re: File upload... In reply to
You would have to modify the record, similar to the routine in the validate mod.

I wouldn't think it would be necessary, though. All you need to do is to check whether a file matching the key value of the record exists.


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





Quote Reply
Re: File upload... In reply to
I just meant, that the default value of the field = 'no' and when there's been added i graphic, it must change to 'yes'.
I think this routine must happen in the sub 'file_upload_succes'. Could it be ???
I will some thing be depended of the value of that field, so for ex. a maximum of adding graphics, lets say a user can add max. 75 records, I will let him max. add 30 graphics, also in my short display, now produce a 'camera', when a user adds a URL of where his graphic is. I will keep this options, if its possible, I think, when my 'foto_field' is loaded it could. OK???

[This message has been edited by mart (edited August 22, 1999).]
Quote Reply
Re: File upload... In reply to
If that's what you need, yes, it would probably be fine to add the code to sub html_file_upload_success.



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





Quote Reply
Re: File upload... In reply to
Can you point me in the good direction, where to start?? I think I have troubles to open the db and write a 'yes' in the 'foto-field'.

Thanks in advance.
------
Mart.
Quote Reply
Re: File upload... In reply to
I'll see about it tomorrow. I just can't write any code today.


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





Quote Reply
Re: File upload... In reply to
Here's something you can try. Be sure to change the first line to match the field number of the field that indicates whether a photo has been uploaded.

Code:
$db_pic_field = 6;
open (DB, "<$db_file_name") or &cgierr("error.
unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $in{$db_key}) {
$data[$db_pic_field] = "Yes";
%hash = &array_to_hash(0,@data);
$output .= &join_encode(%hash);
}
else {
$output .= $line . "\n";
}
}
open (DB, ">$db_file_name") or &cgierr("error.
unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB $output;
close DB;


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





Quote Reply
Re: File upload... In reply to
I know what you mean, Mart. I'm a little bit, as we say in America, "under the weather" myself.

Let me know if it works. Smile


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





Quote Reply
Re: File upload... In reply to
Well, coming slowly 'up' the weather.
To implant the mod gives no problems, the field is loaded but I try to load the field with the URL of the graphic, that will not succeed. I am pretty sure, that there is a def. of the URL of the graphic somewhere, but the $extension will not load. The value of the $in{$db_key} is good, also the $SAVE_DIRECTORY_URL will display. How can I take the whole URL of the graphic at once and put it in my foto_field???
Quote Reply
Re: File upload... In reply to
Thank you, it looks good, I will try this, when I'll be better, I'm a little bit sick today.

Greetings,
--------
Mart.
Quote Reply
Re: File upload... In reply to
I misunderstood what you wanted to do.

This is the only way I can figure out how to get the URL of the photo into your database.

Instead of

$data[$db_pic_field] = "Yes";

use

Code:
if (-e "$SAVE_DIRECTORY/$data[$db_key_pos].gif") {
$data[$db_pic_field] = "$SAVE_DIRECTORY_URL/$in{$db_key}.gif";
}
elsif (-e "$SAVE_DIRECTORY/$data[$db_key_pos].jpg") {
$data[$db_pic_field] = "$SAVE_DIRECTORY_URL/$in{$db_key}.jpg";
}




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





Quote Reply
Re: File upload... In reply to
No. When a graphic is overwritten, it no longer exists.


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





Quote Reply
Re: File upload... In reply to
Just two more things,
Is it possible to make a 'delete' function, for users, who added a graphic, which must be deleted and when a graphic is overwrite, the old one is displayed in the 'upload_succes' display, I rather see that the new added one display. Could it be???
Quote Reply
Re: File upload... In reply to
I think the problem is in the $extension variable.

You might try

unlink "$SAVE_DIRECTORY/$in{$db_key}.jpg";
unlink "$SAVE_DIRECTORY/$in{$db_key}.gif";

instead of

Code:
$ALLOWED_EXT =~ s/\\.//g;
$ALLOWED_EXT =~ s/\$//g;
@extensions = split (/\Q|\E/o,$ALLOWED_EXT);
foreach $extension (@extensions) {
(-e "$SAVE_DIRECTORY/$in{$db_key}.$extension") && (unlink <$SAVE_DIRECTORY/$in{$db_key}.$extension> )
}

If there's no file that matches, nothing will happen.

Also, you do *not* want the line

my($db_key);

That could be a major problem.


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





Quote Reply
Re: File upload... In reply to
No, I don't know how, but every variable lost his value, when the script is called wit the submit button 'delete_foto'. I don't have a '$in{db_key}' and also not a '$SAVE_DIRECTORY, how do I have to define them???
Quote Reply
Re: File upload... In reply to
Did you add a line to db.cgi

Code:
elsif ($in{'delete_foto'}) { &delete_foto; }

You'll also need someplace for the script to go after you delete the foto to confirm that the foto was deleted.


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





Quote Reply
Re: File upload... In reply to
Yes, that I had take care of. I've made a new sub in my html.pl, sub html_delete_foto_success and the lines in the script were also added.
Quote Reply
Re: File upload... In reply to
I think I'm close,...
I need the possibility for users, to delete a photo, so I add the following code in my 'html.pl':
Code:
if (($rec{'Foto'}) &&($rec{'Foto'} ne "http://")){
print qq|
<form action="$db_script_url" METHOD="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="db_key" value="$db_key">

<INPUT TYPE="submit" VALUE="Verwijder foto" NAME="delete_foto">|; }
And also the following to the 'db.cgi':
Code:
sub delete_foto {
# --------------------------------------------------------

my($db_key);

$ALLOWED_EXT =~ s/\\.//g;
$ALLOWED_EXT =~ s/\$//g;
@extensions = split (/\Q|\E/o,$ALLOWED_EXT);
foreach $extension (@extensions) {
(-e "$SAVE_DIRECTORY/$in{$db_key}.$extension") && (unlink <$SAVE_DIRECTORY/$in{$db_key}.$extension> )
}


&html_delete_foto_success($in{$db_key});

}
but the value of $in{db_key} will not load, I think, when I replace the code in the script with this:
Code:
sub delete_foto {
# --------------------------------------------------------

unlink "/opt/guide/www.autorandstad.nl/foto/10.jpg";

&html_delete_foto_success($in{$db_key});

}
it will delete number 10, just like I will. What am I missing???
Quote Reply
Re: File upload... In reply to
Still not solved...
Quote Reply
Re: File upload... In reply to
I don't know what to tell you, Mart. I'm afraid that your database has become so complex that I can't follow what you're doing any more. I'm sorry.


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





Quote Reply
Re: File upload... In reply to
I'm only trying to make a possibility to delete a graphic. I need it, because I have give registered users a maximum of adding graphics. I think they must have the possibility to delete older added graphics just in a regular way.
I nearly succeed, but only the 'transfer' of the '$rec{$db_key}' will not succeed. I mean the transfer from the sub 'html_modify_record_form' to the script, a new added sub 'delete_foto'. There the $rec{db_key} is empty. If I only knew, how to transfer that value of the variable, I can try further.

Thanks in advance.
----------
Mart.
> > > >