SitePoint Sponsor

User Tag List

Page 6 of 8 FirstFirst ... 2345678 LastLast
Results 126 to 150 of 181
  1. #126
    Ramzi
    SitePoint Community Guest
    I have a permissions problem. Anytime I try to create a file through a cgi script running in a browser, I get a permissions error. If I simply do a

    open my $outputFile, ">test.txt" or die "Can't open file $!\n";

    It dies and returns
    Can't open file Permission Denied.

    How can I set the permissions correctly?

  2. #127
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't get the temp file to be saved into the folder I created for uploads.

    here's the errors I'm getting:
    Code:
    [Wed Mar 21 19:09:43 2007] [error] [client 127.0.0.1] binmode() on closed filehandle UPLOADFILE at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/upload.cgi line 16., referer: http://localhost/upload.htm
    [Wed Mar 21 19:09:43 2007] [error] [client 127.0.0.1] print() on closed filehandle UPLOADFILE at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/upload.cgi line 20, <fh00001avatar.gif> line 1., referer: http://localhost/upload.htm
    [Wed Mar 21 19:09:43 2007] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/uploads/avatar.gif, referer: http://localhost/cgi-bin/upload.cgi
    Everything else is working fine, the file's just not getting saved correctly, which causes the third error, and because of that it won't display on the confirmation Web page.

    I hope this isn't dead.

  3. #128
    SitePoint Zealot elated's Avatar
    Join Date
    Dec 2004
    Location
    Sydney, Australia
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The obvious things to check are (a) that the path to your uploads folder is correct in your script, and (b) that your webserver user has permission to create and modify files in the uploads folder.

    Matt

  4. #129
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm running apache 2.2 on a windows machine. How would I go about changing the permissions?

    Or is it possible to use chmod, or something similar, to allow this script only access to the folder? If it is, how?

  5. #130
    alexgein
    SitePoint Community Guest
    chmown the directory to be the same user/group as your perl files are run as. In most cases its the same user as apache (ie. apache/apache).

    then tighten the directory so it can only be written to by that user.

  6. #131
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put it on my online server, cause I wasn't sure how to do a chown with apache on windows. I'm not getting any errors now, but it's not working. The thank you page is pointing to the right directory and everything when you look at the images properties so I'm pretty sure all the directories are right. Nothing is being put in the upload folder though.

    here's my directory structure:
    /public_html/perupload.html
    /public_html/cgi-bin/upload.cgi
    /public_html/upload/filename

    and here's the script as it is on the server:
    Code:
    #!/usr/bin/perl -w
    
    use CGI;
    
    $upload_dir = "/upload/";
    
    $query = new CGI;
    
    $filename = $query->param("photo");
    $email_address = $query->param("email_address");
    $filename =~ s/.*[\/\\](.*)/$1/;
    $upload_filehandle = $query->upload("photo");
    
    open (UPLOADFILE, ">$upload_dir/$filename");
    
    binmode UPLOADFILE;
    
    while ( <$upload_filehandle> )
    {
       print UPLOADFILE;
    }
    
    close UPLOADFILE;
    
    print $query->header ( );
    print <<FINISH;
    
    <HTML>
    <HEAD>
    <TITLE>Thanks!</TITLE>
    </HEAD>
    
    <BODY>
    
    <P>Thanks for uploading your photo!</P>
    <P>Your email address: $email_address</P>
    <P>Your photo:</P>
    <img src="/upload/$filename" border="0">
    
    </BODY>
    </HTML>
    
    FINISH
    and here's a test url:
    http://www.heresjonnie.com/perlupload.htm

  7. #132
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this:

    $upload_dir = "/upload/";

    should be:

    $upload_dir = "public_html/upload";

    or whatever the correct full path to the upload folder is. Also note you don't need the trailing slash since you are adding it in later:

    open (UPLOADFILE, ">$upload_dir/$filename");

    all open functions should be checked for success or failure too using "die".

  8. #133
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've made those changes and all of the directory/file permissions are correct, but still no dice.

    I added the "die" to the end of the open function and it's causing an internal server error.

  9. #134
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    Code:
    #!/usr/bin/perl -w
    
    use CGI;
    use CGI::Carp qw/fatalsToBrowser/;
    
    $upload_dir = "$ENV{DOCUMENT_ROOT}/upload";
    
    $query = new CGI;
    
    $filename = $query->param("photo");
    $email_address = $query->param("email_address");
    $filename =~ s/.*[\/\\](.*)/$1/;
    $upload_filehandle = $query->upload("photo");
    
    open (UPLOADFILE, ">$upload_dir/$filename") or die "Can't open: $upload_dir: $!";
    
    binmode UPLOADFILE;
    
    while ( <$upload_filehandle> )
    {
       print UPLOADFILE;
    }
    
    close UPLOADFILE;
    
    print $query->header();
    print <<FINISH;
    
    <HTML>
    <HEAD>
    <TITLE>Thanks!</TITLE>
    </HEAD>
    
    <BODY>
    
    <P>Thanks for uploading your photo!</P>
    <P>Your email address: $email_address</P>
    <P>Your photo:</P>
    <img src="../upload/$filename" border="0">
    
    </BODY>
    </HTML>
    
    FINISH

  10. #135
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You rock dude. ROCK!

    I'm guessing it's the "$ENV{DOCUMENT_ROOT}" bit that helped out.
    What's the use "CGI::Carp qw/fatalsToBrowser/;" part.

  11. #136
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by epix View Post
    You rock dude. ROCK!

    I'm guessing it's the "$ENV{DOCUMENT_ROOT}" bit that helped out.
    What's the use "CGI::Carp qw/fatalsToBrowser/;" part.

    http://perldoc.perl.org/CGI/Carp.html

    $ENV{DOCUMENT_ROOT} is the path to the root directory, it was worth a try.

  12. #137
    kaosfalco
    SitePoint Community Guest
    he looks like manson!

  13. #138
    SitePoint Member
    Join Date
    May 2007
    Location
    Victoria BC area Canada
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have been following the script laid out in this forum and have set my directory at
    http://www.example.ca/cgi-bin/upload.cgi
    but I keep getting an error

    The requested URL /cgi-bin/example.ca//upload.cgi was not found on this server. can anyone help?
    Last edited by heirlooms; Jun 6, 2007 at 07:19.
    'There is nothing either good or bad, but thinking makes it so'

    Hamlet 1601

  14. #139
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is not a good path:

    /cgi-bin/example.ca//upload.cgi

    is that what you have in your form tag in the action attribute?

    <form action=?>

    change it to:

    <form action="cgi-bin/upload.cgi">

  15. #140
    casy
    SitePoint Community Guest
    When I submit the form, I got an internal error. I have no clue y I got that, maybe becuz the upload_dir? My url is somethin like: http://lab.xx.yy.zz/~myname/upload.html
    , and I put the .pl in http://lab.xx.yy.zz/~myname/cgi-bin/upload.pl, I would like to upload the file under the ./cgi-bin/scheduleFile. Could you plz tell me what should I put in the upload_dir? Thank you so much.

  16. #141
    SitePoint Zealot elated's Avatar
    Join Date
    Dec 2004
    Location
    Sydney, Australia
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Casy, try KevinR's (excellent) code, posted on Mar 25, 2007 03:28. That should at least tell you what the exact problem is.

  17. #142
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe everyone see the times/dates in posts a little different, so it's probably better to reference the post number. I think you are refering to post #134

  18. #143
    SitePoint Zealot elated's Avatar
    Join Date
    Dec 2004
    Location
    Sydney, Australia
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops! Thanks Kevin

  19. #144
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is an uploader script that is more robust than the one discussed in Matt Doyles article: "Uploading Files Using CGI and Perl". I would urge anyone that needs a basic file uploader to use this script instead of the script in the article. It can be used as a drop-in replacement for Matts script.

    Code Perl:
    #!/usr/bin/perl -T
     
    use strict;
    use warnings;
    use CGI;
    use CGI::Carp qw/fatalsToBrowser/;
    use File::Basename;
     
    # set the maximum limit for file uploads  
    $CGI::POST_MAX = 1024 * 5000; #adjust as needed (1024 * 5000 = 5MB)
     
    # change to 1 (one) to disable file uploads 
    $CGI::DISABLE_UPLOADS = 0; #1 disables uploads, 0 enables uploads
     
    my $query = new CGI;
     
    unless ($CGI::VERSION >= 2.47) { 
       print $query->header(),
             $query->start_html(),
             'Your version of CGI.pm is too old. You must have verison 2.47 or higher to use this script.',
             $query->end_html;   
       exit(0);
    }
     
    my $upload_dir = "/home/mywebsite/htdocs/upload";
     
    # a list of valid characters that can be in filenames
    my $filename_characters = 'a-zA-Z0-9_.-';
     
    my $file = $query->param("photo");
    my $email_address = $query->param("email_address");
     
    # get the filename and the file extension
    # this could be used to filter out unwanted filetypes
    # see the File::Basename documentation for details
    my ($filename,undef,$ext) = fileparse($file,qr{\..*});
     
    # convert spaces to underscores "_"
    $filename =~ tr/ /_/;
     
    # remove illegal characters
    $filename =~ s/[^$filename_characters]//g;
     
    # append extension to filename
    $filename .= $ext;
     
    # satisfy taint checking
    if ($filename =~ /^([$filename_characters]+)$/) {
       $filename = $1;
    }
    else{
       print $query->header(),
             $query->start_html(),
             'The filename is not valid. Filenames can only contain these characters: $filename_characters',
             $query->end_html;
       exit(0);
    }  
     
    my $upload_filehandle = $query->upload("photo");
     
     
    open (UPLOADFILE, ">$upload_dir/$filename") or die "$!";
    binmode UPLOADFILE;
    while ( <$upload_filehandle> ) {
       print UPLOADFILE;
    }
    close UPLOADFILE;
     
    print $query->header(),
          $query->start_html(-title=>'Upload Successful'),
          $query->p('Thanks for uploading your photo!'),
          $query->p("Your email address: $email_address"),
          $query->p("Your photo $filename:"),
          $query->img({src=>"../uploads/$filename",alt=>''}),
          $query->end_html;

  20. #145
    SitePoint Zealot elated's Avatar
    Join Date
    Dec 2004
    Location
    Sydney, Australia
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice one Kevin - looks good

    Hmm, maybe I should update the article a bit! Certainly using CGI::Carp would help to reduce the number of questions in this topic

    Matt

  21. #146
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Matt,

    I did not realize that "Elated" was you Matt. I really think it would be a good service to the readers/users to update the article and the script.

    Kevin

  22. #147
    YB
    SitePoint Community Guest
    Thanks Kevin that is finally after searching everywhere, a script that working.

  23. #148
    Jamshed
    SitePoint Community Guest
    cool stuff..
    it was really very much helpful for me
    thanks allot dude

  24. #149
    jk
    SitePoint Community Guest
    gud hints to work upon

  25. #150
    swapnil
    SitePoint Community Guest
    its very good docs.full ,step by step explainnation


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •