Gossamer Forum
Home : Products : DBMan : Customization :

File-upload questions

Quote Reply
File-upload questions
Two questions:
1. The file upload seems to work fine, however, if you originally had a .gif file, and subsequently upload a .jpg file, the .gif file remains, and as it is the first to be hit in the loop to see if there is a graphic corresponding to the userid, it remains. Is there a way to ensure that the first file is eliminated, regardless of the file format of the subsequent uploads?

2. I have the $rec{'Modified'}=&get_date;
line which updates my Modified field when the record is changed; where and how would I implement that to also update Modified when a graphic is successfully uploaded?

PS I noted at the end of the upload thread (where I probably should have posted this in the first place) that you have a new version as of today (6/8) While what you sent me seems to be working fine for me, I did get an e-mail from someone else trying to upload a .jpg file that he got a cgi error. I asked him to try to reproduce it and send me the error message. Are there any changes in your newest version that I need?
thanks

David

[This message has been edited by dperkins (edited June 08, 1999).]
Quote Reply
Re: File-upload questions In reply to
1 -- It didn't occur to me that it might be a problem. I'll go have a look at it and see if I can add a "delete before add" routine, rather than just an overwrite.

2 -- I'm not sure where you would put a date change routine when a new file is uploaded. Since the record and the file are separate forms, I don't know how it would be possible.

There have been no changes in the file-upload mod. I just posted about it today because I had received some pretty good response from the folks who had written to me to ask for it and I thought it was just easier to post the links rather than having to send emails to each person who wanted the scripts.

When you get the cgi-error message, I'd be really pleased to see it.


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





Quote Reply
Re: File-upload questions In reply to
They finally got back to me - not with the error message, but with the file - which had an invalid name - "sam & trigger" no extension, no nothing. I'm not surprised it threw an error. I suspect your trap at a minimum expects to find an extension.

P.S. - Have you figured out a delete before add routine to prevent the problem of not picking up a newly uploaded .jpg when a .gif already exists?
Quote Reply
Re: File-upload questions In reply to
No, I'm sorry I haven't. When I made a change to get it to work, I couldn't upload anything.

I really don't know what the problem is. I can't even upload a second file now, with the original script. I don't know if it's something with my server or something with my script.


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





Quote Reply
Re: File-upload questions In reply to
If I ever get back to working on my own site, I'll have links to it available. Smile

The instruction file is at

http://www.jpdeni.com/dbman/file-upload.txt

Follow the instructions carefully.

I won't guarantee that it will work for you. Some folks have had problems and I don't know why.

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





Quote Reply
Re: File-upload questions In reply to
I finally got the thing figured out for deleting old files before the new one is uploaded. (Took me long enough! Smile )

You can pick up the new version of the file-upload script at

http://www.jpdeni.com/dbman/file-upload_cgi.txt



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





Quote Reply
Re: File-upload questions In reply to
how do i use the file-upload_cgi ?
Quote Reply
Re: File-upload questions In reply to
Hi, I don't know exactly what you are talking about. because I'm beginner on this site.

Let me just give you a sample idea how to delete old files when you upload new files.

I am talking about when you modify or delete a html file, and the html file include some gif files or so.

First, you have to save the uploaded file name at any data file when you create the html-file.


If there are saved category(directory)name, html-file name and gif file names like "cat&&html&&file-name1&&file-name2.....more..." on data file,

# at modify or del page add this line.
&unlink_files;

# and make sub...
sub unlink_files {
local ($categorys,$html) = @_;
open(FILE, "$dir-path/$category/$data\.txt") | | die "I can't open "$dir-path/$category/$data\.txt \"Check it for this error\"\n";
flock (FILE, 1) or die "can't lock data file\n";

while(<FILE> ) {
chop;
@all = split(/\n/);

foreach $line (@all) {
($category-value, $html-value, $file-name1-value, $file-name2-value, $....more...) = split(/&&/, $line);
if($default-file eq "ex.gif") {}
# so, an important file is not deleted.
else {
unlink "$dir-path/$category/file-name1-value";
unlink "$dir-path/$category/file-name2-value";
unlink ......more.....more...
}
}
}
close(FILE);
}

Quote Reply
Re: File-upload questions In reply to
I already have it fixed. But thanks! Smile



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





Quote Reply
Re: File-upload questions In reply to
i wanted that the uploaded file be saved with the same filename. for example, i uploaded "hello.txt", it should be uploaded as "hello.txt" as well.

how am i supposed to do that????
Quote Reply
Re: File-upload questions In reply to
i have already solved that problem by disabling the "allowed extension option" and commenting the next two lines following $Filename = $1.

now i have another problem. i have a field in my database (URL) that shld contain the url of the saved filename. how can i store the value of the $filename, plus the web server address of course, to the $rec{'URL'} file?

please help......
Quote Reply
Re: File-upload questions In reply to
I'm not sure what you did or why. The whole point of the mod was to save the file as the same name as the key for the record so the two would be connected.


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





Quote Reply
Re: File-upload questions In reply to
 
i wanted to presserve the original filename that is why i made such change to the mod. my problem now is how to store the filename in one of the fields of the record.

JP, please help me......
Quote Reply
Re: File-upload questions In reply to
You'll have to modify the record, then, after the file is uploaded.

Are you getting the record displayed after the upload?

If not, I don't know what to tell you. If so, the following might work:

Move

Code:
$SUCCESS_LOCATION = "$db_script_link_url&$db_key=$rec{$db_key}&upload_success=1";

to

Code:
print $query->redirect($SUCCESS_LOCATION);

so that the latter line now reads

Code:
print $query->redirect("$db_script_link_url&$db_key=$rec{$db_key}&upload_success=1
&new_filename=$File_Handle");

Note that I'm also passing the name of the file (I think) to the upload success page. Be sure to leave "new_filename" as it is. Don't change it to the name of your filename field.

In html_upload_success, right at the beginning, add

Code:
%rec = &get_record($in{$db_key});
foreach $column ($db_cols) {
$in{$column) = $rec{$column};
}
$in{'FileName'} = $in{'new_filename'};
&modify_record;

Then delete the rest of html_upload_success. You should be taken to html_modify_success after the record is modified.

Be sure to change FileName to the name of your field that holds the file.

I don't know if this will work or not.

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







[This message has been edited by JPDeni (edited July 14, 1999).]
Quote Reply
Re: File-upload questions In reply to
JP,

i can display the other fields successfully but the field that contains the filename remains blank Frown

help me with this, pleaaasssseeee....
Quote Reply
Re: File-upload questions In reply to
Then try

&new_filename=$filename

I don't know what the variable is that holds the filename. I'm guessing here.



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





Quote Reply
Re: File-upload questions In reply to
i have included the other fields as well in the upload_success mod so that it goes something like this:

$in{'Filename'} = $in{'new_filename'};
$in{'Field1'} = $rec{'Field1};
.
.
.

it was supposed to have been done by the foreach loop, right?
Quote Reply
Re: File-upload questions In reply to
You can list them individually. The foreach loop is just less typing. Does the same thing.

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