eoin has asked for the wisdom of the Perl Monks concerning the following question:
I've recently had quite a few problems with this cgi upload script, as you can see here and finnaly when i'm sure I have it figured I get one last stumpper!!
I've looked into the docs for CGI.pm but I couldn't find a solution to my problem. After a bit of pondering i'v discovered that the script will work(or a least I hope so) from a *nix run because they use / as there directory structure dividers but windows use \ and the way my script works it seems to interpolate the whole file name string taken in by the %pics.
So what should be " C:\WINDOWS\Profiles\eoin\My Documents\images\border.jpg" Acctualy becomes "C:WINDOWSProfilesoinMy Documentsimageorder.jpg"
Before I get a chance to stip the filepath from the filename. And obviously the stripping process won't work anymore because there is nothing to strip from. (I.e no \). Is there anyway to fix this without changing alot of the script.
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use CGI; my %pics; my @pic_filehandles; my @filelist; my $key; my @files; my $upload_dir; my $q = CGI->new; my $user = $q->param("user"); my $album = $q->param("T1"); unless ( -d "./albums/$album" ) { mkdir( "./albums/$album", 0775 ); $upload_dir = "./albums/$album"; } { $pics{"pic$_"} = $q->param("photo$_") for 0..13; @pic_filehandles = map { $q->upload("photo$_") } '',0..13; } strip_filename(); sub strip_filename{ my @allkeys = sort(keys(%pics)); foreach $key (@allkeys) { $pics{$key} =~ s/.*[\/\\](.*)/$1/; } } my $cntr = 0; @files = sort(keys(%pics)); foreach $key (@files) { open IMAGE, ">$upload_dir/$pics{$key}"; binmode IMAGE; while (<$pic_filehandles[$cntr]>) { print IMAGE; } close IMAGE; $cntr += 1; } print $q->header ( ); print <<END_HTML; <HTML> <HEAD> <TITLE>Thanks!</TITLE> </HEAD> <META HTTP-EQUIV="refresh" CONTENT="05;URL=http://eoinmurphy00.netfirm +s.com/cgi-bin/main.cgi?status=home&user=$user"> <title>Please Wait</title><head>Thank you for uploading your Photos.<b +ody>Please Wait<br>You will be redirected to the main page in 2 secon +ds.<br>Thank You $user</body> </HTML> END_HTML
If everything seems to be going well, you obviously don't know what the hell is going on.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lost Backs\ash
by diotalevi (Canon) on Aug 14, 2003 at 11:43 UTC | |
by eoin (Monk) on Aug 14, 2003 at 12:35 UTC | |
|
Re: Lost Backs\ash
by bm (Hermit) on Aug 14, 2003 at 11:11 UTC | |
|
Re: Lost Backs\ash
by cfreak (Chaplain) on Aug 14, 2003 at 13:36 UTC |