Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

File Upload On Windows 8 and Perl

by skosterow (Novice)
on Jul 04, 2015 at 15:31 UTC ( [id://1133158]=perlquestion: print w/replies, xml ) Need Help??

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

Greetings!

I'm having a heck of a time and Im not sure I'm not the idiot.

Im using http://www.sitepoint.com/uploading-files-cgi-perl/ script EXACTLY as it is on a Windows 8 box.

I see the file name upload into my upload directory BUT THERE IS NOT DATA IN IT :( In other words I see the file being created, the file name / file is there but the image is not! Its like its a blank .jpg file (or .gif)

Anyone else having this Issue? ill post code but its EXACTLY like the one on the URL i submitted - Thank you Guys/Gals in advance for ANY help!

Also - The directory rights are set - "Full Control" for the IUSER! So i KNOW thats not the issue - besides it creates the file but NO data grrrr! :)

Replies are listed 'Best First'.
Re: File Upload On Windows 8 and Perl
by marinersk (Priest) on Jul 04, 2015 at 15:47 UTC

    Well, the code and HTML looks fairly straightforward; it does use a technique different than the one I tend to use.

    I know you're certain you've made no errors, but I'm afraid for me to troubleshoot further, I'd need to see the HTML of the web page, the script as you have it, and precisely what you've entered into the web form.

    Perhaps a more talented Monk will come along and be able to infer more without these things.

    If I might trouble you to post the codes and inputs, great. If not, good luck in the hunt.

      okay this is wired! I GET THE SAME result with that script you showed me - ummm this HAS to be something my servers doing?? any suggestions??

        I suspect you will have found it upon re-reading the thread, but just in case, see my reply above at Re^5: File Upload On Windows 8 and Perl.

        Further note, you seem to be mixing slashes and backslashes in your filename -- I'm a stickler for consistency, admittedly often beyond what is needed, but experience has taught me that computers and inconsistency mix badly at times.

        Finally, if adjusting the filename string the way you think you should doesn't fix the issue, you might consider having the script display its values to the browser before initiating the actual upload, just to make sure there isn't something else amiss. Input filename, output filename -- anything that could matter. Do not fall again for the trap of presuming to know what does matter. When stuff is broken, it pays to be extremely circumspect.

        print "Content-Type: text/html\n\n"; print "<!DOCTYPE html>\n"; print "<html>\n"; print " <head>\n"; print " <title>My CGI File Upload Test</title>\n"; print " </head>\n"; print " <body>\n"; print " <p>\n"; print "\$upload_dir = [$upload_dir]<br />\n"; print "\$filename = [$filename]<br />\n"; print "\$upload_dir/\$filename = [$upload_dir\/$filename]<br />\n" +; print " </p>\n";

        Another tidbit I ran into from my own experiences -- if the server is a Windows server, sometimes they don't set permissions on TEMPthe way you'd expect, and the CGI uploader temporarily writes there. Total upload failure if you don't have write permissions to the TEMPdirectory. A workaround is to establish a different directory for it to work with as its workspace:

        # Needed to avoid dependence on C:\TEMP being world read+write BEGIN { $TempFile::TMPDIRECTORY = './'; }

        It's been my experience that using './'for $TempFile::TMPDIRECTORYtends to result in the cgi-binor similar directory being used -- but it depends on where your Perl CGI script lives -- in your case, I seem to recall your form invokes it from /test/, so make sure your script has write permission there, or change the value used for $TempFile::TMPDIRECTORY.

      Thanks mate! i posted the form above, but i will try using your version and see if i get the same result - then at least i know its my server - not my code hehehe

        To be fair, even if you change the framework, it is always possible -- I would even go so far as to say "likely" -- that you would replicate a logic error (or a typo, like, say, neglecting to double your backslashes inside a quoted string) in the part of the code you have to supply to make a snippet like that work. It seems like changing the framework and getting the same error would implicate the site, but that's not as sure a bet as you'd think.  :-)

Re: File Upload On Windows 8 and Perl
by marinersk (Priest) on Jul 04, 2015 at 20:14 UTC

    Okay, I've gotten far enough that we should multi-thread a bit, each doing our own thing

    I've modified your code; can you save off your version and work with this one a bit?

    For me it is failing but I've gotten far enough that it's telling me where and why it's failing so I can chase down environmental issues on my side.

    Don't forget to change some of the hard-coded values, such as the CGI script name in the HTML file and output directory in the Perl script, etc.

    The updated HTML file:

    The updated Perl script:

    Results:

    ############################################### # CGI IN $query = [CGI=HASH(0xb72b4ec)] $submit = [Submit Form] $user_id = [marinersk] $filename = [Humor-Fake-Doctor-001a.bmp] $safe_filename_characters = [a-zA-Z0-9_.-] $upload_dir = [.] $CGI::POST_MAX = [5120000] ############################################### #################################################### ##################### Main Page #################### #################################################### $abtflg = [0] $name = [] $path = [./] $extension = [Humor-Fake-Doctor-001a.bmp] $filename = [Humor-Fake-Doctor-001a.bmp] $filename = [Humor-Fake-Doctor-001a.bmp] $filename = [Humor-Fake-Doctor-001a.bmp] $filename = [Humor-Fake-Doctor-001a.bmp] $upload_filehandle = [Humor-Fake-Doctor-001a.bmp] $output_filename = [./Humor-Fake-Doctor-001a.bmp] No such file or directory $open_ret = [] Error opening output file "./Humor-Fake-Doctor-001a.bmp" $abtflg = [1]

    So I'll play with it a bit on my end, but could you use this as the basis for your work for a bit so we can isolate the problem?

    Update: Added the updated HTML file as well

      Oops.

      Left out the filename for the openafter extracting it to its own scalar for debugging purposes. Now mine is sitting and spinning; it may be uploading the file, hard to tell.

      my $open_ret = open ( UPLOADFILE, ">" ) or print "$!\n"; my $open_ret = open ( UPLOADFILE, ">", $output_filename ) or print "$! +\n";

      Okay, mine timed out now.

      I'm going to rip everything out and start over from the template, avoiding all the added features you've tossed in (usernames and crypt keys and unreferenced DBI modules, oh my!).

      I try not to be a NIH* guy, but sometimes you just gotta' rebuild the wheel to see how it keeps the chandelier floating at the Shindig.

      *Not Invented Here

Re: File Upload On Windows 8 and Perl
by marinersk (Priest) on Jul 04, 2015 at 21:59 UTC

    Okay, going back to the script and HTML file as written at http://www.sitepoint.com/uploading-files-cgi-perl/the upload now works on my site.

    I have family commitments for tonight for Independence Day, so I will pick this up as opportunity permits. I would recommend you proceed thus:

    1. Take these two files, adjust only what is needed to make it work on your site -- no functionality changes.
    2. Add one feature from your version at a time, testing each as you go.
      • Don't get in a hurry.
      • Add the module but no other code changes -- make sure something isn't getting exported which is killing you.
      • If just adding module causes no behavior changes, only then proceed. Make small changes for feature addition, and keep re-testing. Find out which piece breaks it.

    The HTML file:

    The Perl script:

      I FOUND IT!

      right after I add:

      if ($user_id eq '') { my $cookie = CGI->new; $user_id = $cookie->cookie('TEC_USER_ID'); my $crypt = Crypt::Lite->new( debug => 0, encoding => 'hex +8' ); my $decrypted = $crypt->decrypt($user_id, $ip_address) +; $user_id = $decrypted; }

      The damned thing does its crap again! WOOT WOOT! Now at least I know what it is and can code around! Already submitted a bug in MY bugzilla - this will be something to have fun with after the project's done!

      Thanks to EVERYONE that helped!

      Mods PLEASE DONT close this thread! May take me a min but I WILL trace this down and find out why and post! Less some one beats me to it! Thanks again gays / gals!

        FYI: We don't close threads. I'm not sure anything ever truly goes away at PerlMonks.

      Well hell! there's def something amiss here cause IT WORKED! Okay there MUST be something in the code that goes AROUND this that THAT dont like - okay ill start adding and then re-post. Umm maybe found some mod - incompatibility!LOVE TO FIND BUGS! thanks again mate!

      okay thanks mate! i will do this now - yeah the 4th kinda stopped me too! thanks for all the help! give me a few and ill post results!

Re: File Upload On Windows 8 and Perl
by Anonymous Monk on Jul 05, 2015 at 08:10 UTC

      <pocket type="todo">
        Thank you.
      </pocket>

Re: File Upload On Windows 8 and Perl
by marinersk (Priest) on Jul 04, 2015 at 15:36 UTC

    Will take a look -- but be careful about what you "know" to be true, as that's where the bugs usually hide.  :-)

      thanks - again i can post the exact code but its exactly like that site - I created a test script off the main site when i was having issues implementing the upload feature :)

        Gut instinct with nothing to back it -- can you give me exactly what is in the form fields at the time you click the submit button?

        Where I'm going with this: It seems fairly likely that it is opening the file and then dying for some reason, thus leaving you with an empty file. Perhaps it's having trouble parsing the input filename, in some manner which is not made visible to you despite all the wonderful efforts in the example to get the errors back to you; or once opened, it is having trouble finding a channel back to the input data from your file.

        If nothing pops out at me with your supplied data, maybe I can spin up a quick version of the file uploader as you have done and troubleshoot it from this side.

Re: File Upload On Windows 8 and Perl
by marinersk (Priest) on Jul 04, 2015 at 18:33 UTC

    Okay, you've got a number of threads in this conversation which have details you haven't had a chance to look into, so I'm going to let you do that and stop spamming you with ideas.

    I am going to take your code, tweak it to use at my web site, and build a site to mirror your efforts.

    Assuming it works on my site, I'll start adding debugging features which I can then ship back to you to try.

    I suspect I'm going to feel really silly about something basic we've overlooked when this is all said and done.

    See you in a bit.

      I agree Ive been perling for 10 years now and im freaking STUMPED!
Re: File Upload On Windows 8 and Perl
by skosterow (Novice) on Jul 04, 2015 at 19:09 UTC

    this is DEF a script error! I got the SAME result on a IIS 6 server! so the permissions are NOT the issue grrrrrr

      Please run perl -cagainst your script. I'm getting odd errors over here.

Re: File Upload On Windows 8 and Perl
by skosterow (Novice) on Jul 04, 2015 at 18:34 UTC
    Okay im gonna put THIS code on a IIS 6 server and see what happens! Ill post the result!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found