Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

uploading to a different directory

by mojobozo (Monk)
on Nov 07, 2002 at 16:30 UTC ( #211101=perlquestion: print w/ replies, xml ) Need Help??
mojobozo has asked for the wisdom of the Perl Monks concerning the following question:

My fellow monks, I found a quick upload script and it's working fine. It's uploading the files to the wwwroot dir on my system. I even changed it so that it's doing it to the correct file name/type instead of just a txt file as it was when I found it. My question is how can I have it upload to a different directory? Right now, it does it thusly (where $base = filename.type):
open FILE, ">$base"; binmode FILE; while (<$file>) { print FILE $_; $length += length($_); }

I tried this:
$upload_path = "\uploaded_files\"; $uploaded_file .= $upload_path + $base; open FILE, ">$uploaded_file"; binmode FILE; while (<$file>) { print FILE $_; $length += length($_); }

but it didn't work. I'm not sure how to go about acomplishing this. Do I need to escape the "\" in $uploaded_path? Can you lend a hand?
_____________________________________________________
mojobozo
word (wrd)
interj. Slang. Used to express approval or an affirmative response to
something. Sometimes used with up. Source

Comment on uploading to a different directory
Select or Download Code
Re: uploading to a different directory
by fglock (Vicar) on Nov 07, 2002 at 16:37 UTC
    print "Filename is: $uploaded_file \n";

    will tell you what the system thinks the filename is.
    You do have to escape \\ , or use / instead.

      Went back and added the line to see what it thought the path was and it came up "0", so I went and looked at the .= code again and noticed it was wrong. Now I'm using
      my $uploaded_path = "\\Inetpub\\wwwroot\\uploaded_files\\"; $uploaded_path .= $base; print h2('Uploaded Path'),$uploaded_path; open FILE, ">$uploaded_path"; binmode FILE;

      and it works fine. As you can see above, I also esacped the \'s. Thanks!!
      _____________________________________________________
      mojobozo
      word (wrd)
      interj. Slang. Used to express approval or an affirmative response to
      something. Sometimes used with up. Source
Re: uploading to a different directory
by iburrell (Chaplain) on Nov 07, 2002 at 17:12 UTC
    BTW, you shouldn't use <$file> and print if you are just copying the file. Especially if the file is a binary file. You set binmode which is good so it won't change end-of-line characters. But copying line-by-line is slower because the input must be scanned for end-of-line characters. If you just want to copy the file, use read and print with a fixed buffer size as large as you can get away with.
    while ($bytesread=read($filename,$buffer,1024)) { print OUTFILE $buffer; }
    (Code is from the CGI man page).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-08-28 02:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls