Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Upload problems

by eoin (Monk)
on Aug 13, 2003 at 10:35 UTC ( [id://283501]=perlquestion: print w/replies, xml ) Need Help??

eoin has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,
I'm back again to ask for your wisdom.
I posted a question, here, about a file upload script. That question was refering to syntax errors, these errors were solved thanks to Jeurd and a few others. Although the syntax is okay, it seems the script isn't.
When I tried to upload some images files(JPEG) all I got were a few text files with the local path to the image in it(i.e. the path to the image on the comp of the person who tried to upload it). Although the slashes were gone the C:windowsmydocuments....... etc etc was still there. I quite stumped at the moment.
I seached around and didn't find any similar probs and I've had a good hard look at the script but I can't see anything wrong(although this is my firist upload script.)
If you find anything wrong please leave a reply. All help is greatly aprieciated.
Thanks in advance.
I'm going back to try find the problem again.

The codes inside

All the Best, Eoin...

If everything seems to be going well, you obviously don't know what the hell is going on.

#!/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

Replies are listed 'Best First'.
Re: Upload problems
by cfreak (Chaplain) on Aug 13, 2003 at 13:16 UTC

    I don't see anything obviously wrong with your script, however check the upload form and be sure that you have

    enctype="multipart/form-data"
    in your form tag, i.e.:
    <form method="POST" action="yourscript.pl" enctype="multipart/form-dat +a">
    The browser will not upload the images unless you have that.

    Lobster Aliens Are attacking the world!
Re: Upload problems
by rupesh (Hermit) on Aug 13, 2003 at 12:55 UTC
    I was hunting information while working with perl cgi and I found this site and thought it would be of some use...
    It has a link for file uploads as well as other functionalities..

    we're born with our eyes closed and our mouths wide open, and we spend our entire life trying to rectify that mistake of nature. - anonymous.

      Actually, that's a link to the Perl 4 library for handling CGI programming. I wouldn't recommend anyone start with it. If you need to port some Perl 4 code to Perl 5, it's worth considering, but CGI.pm is definitely a better starting point now.

        Yes i've looked into the docs for CGI.pm but its not there that my problem lays.
        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.
        Thanks for any help in advance.

        All the Best, Eoin...

        If everything seems to be going well, you obviously don't know what the hell is going on.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://283501]
Approved by benn
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-18 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found