#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    2
    Rep Power
    0

    permissions after uploading


    I have a script working to upload images to a certain directory (catalogue-script). Everething works fine accept for the file permissions.
    All uploaded images get the permission rwx-- (700). That's why visitors cannot view them.
    What is wrong?

    After installing the script again:
    first time permissions are set to 755
    second time permissions are set to 744
    third time permissions are set to 700 (duh...)

    Everything worked untill my provider did an upgrade. Can it be a server configuration faillure, or is it in my script?

    #!/usr/bin/perl

    sub addnew {
    use CGI;
    my $req = new CGI;
    open (TEMPLATE, "$varroot/num.txt");
    flock(TEMPLATE,2);
    $totprod=<TEMPLATE>;
    close(TEMPLATE);

    $totprod++;

    $dir = $imagesroot;
    $httpdir = $imageshttp;


    my $file = $req->param('imageloc1');
    my $fileName = $file;
    $fileName =~ s!^.*(\\|\/)!!;
    $newmain = $fileName;

    $addtotprod++;
    if ($file ne "") {
    $prodname1="$totprod"."_big-"."$newmain";
    (open OUTFILE,">$dir/$prodname1");
    binmode(OUTFILE);
    while (my $bytesread = read($file, my $buffer, 1024)) {
    print OUTFILE $buffer;
    }

    close(OUTFILE);
    }
    my $file = $req->param('imageloc2');
    my $fileName = $file;
    $fileName =~ s!^.*(\\|\/)!!;
    $newmain = $fileName;


    $addtotprod++;
    if ($file ne "") {
    $prodname2="$totprod"."_small-"."$newmain";
    (open OUTFILE,">$dir/$prodname2");
    binmode(OUTFILE);
    while (my $bytesread = read($file, my $buffer, 1024)) {
    print OUTFILE $buffer;
    }

    close(OUTFILE);
    }


    my $file = $req->param('imageloc3');
    my $fileName = $file;
    $fileName =~ s!^.*(\\|\/)!!;
    $newmain = $fileName;


    $addtotprod++;
    if ($file ne "") {
    $prodname3="$totprod"."_ex1-"."$newmain";
    (open OUTFILE,">$dir/$prodname3");
    binmode(OUTFILE);
    while (my $bytesread = read($file, my $buffer, 1024)) {
    print OUTFILE $buffer;
    }

    close(OUTFILE);
    }
    my $file = $req->param('imageloc4');
    my $fileName = $file;
    $fileName =~ s!^.*(\\|\/)!!;
    $newmain = $fileName;


    $addtotprod++;
    if ($file ne "") {
    $prodname4="$totprod"."_ex2-"."$newmain";
    (open OUTFILE,">$dir/$prodname4");
    binmode(OUTFILE);
    while (my $bytesread = read($file, my $buffer, 1024)) {
    print OUTFILE $buffer;
    }

    close(OUTFILE);
    }
    my $file = $req->param('imageloc5');
    my $fileName = $file;
    $fileName =~ s!^.*(\\|\/)!!;
    $newmain = $fileName;


    $addtotprod++;
    if ($file ne "") {
    $prodname5="$totprod"."_ex3-"."$newmain";
    (open OUTFILE,">$dir/$prodname5");
    binmode(OUTFILE);
    while (my $bytesread = read($file, my $buffer, 1024)) {
    print OUTFILE $buffer;
    }

    close(OUTFILE);
    }
    my $file = $req->param('imageloc6');
    my $fileName = $file;
    $fileName =~ s!^.*(\\|\/)!!;
    $newmain = $fileName;


    $addtotprod++;
    if ($file ne "") {
    $prodname6="$totprod"."_ex4-"."$newmain";
    (open OUTFILE,">$dir/$prodname6");
    binmode(OUTFILE);
    while (my $bytesread = read($file, my $buffer, 1024)) {
    print OUTFILE $buffer;
    }

    close(OUTFILE);
    }




    $features=$req->param('features');
    $features =~ s/\n/|/g;
    $features =~ s/\r//g;
    $maindesc=$req->param('maindesc');
    $maindesc =~ s/\n/<br>/g;
    $maindesc =~ s/\r//g;
    $shortdesc=$req->param('shortdesc');
    $shortdesc =~ s/\n/<br>/g;
    $shortdesc =~ s/\r//g;
    $ctime=time;
    $itemname=$req->param('itemname');
    $imageloc1=$prodname1;
    $imageloc2=$prodname2;
    $imageloc3=$prodname3;
    $imageloc4=$prodname4;
    $imageloc5=$prodname5;
    $imageloc6=$prodname6;
    $price=$req->param('price');
    $partnum=$req->param('partnum');
    $categories=$req->param('categories');
    open(TEMPLATE, ">$dataroot/$totprod.txt");
    print TEMPLATE "$itemname\n";
    print TEMPLATE "$imageloc1\n";
    print TEMPLATE "$imageloc2\n";
    print TEMPLATE "$imageloc3\n";
    print TEMPLATE "$imageloc4\n";
    print TEMPLATE "$imageloc5\n";
    print TEMPLATE "$imageloc6\n";
    print TEMPLATE "$price\n";
    print TEMPLATE "$partnum\n";
    print TEMPLATE "$categories\n";
    print TEMPLATE "$ctime\n";
    print TEMPLATE "$maindesc\n";
    print TEMPLATE "$shortdesc\n";
    print TEMPLATE "$features|\n";
    close (TEMPLATE);

    open(TEMPLATE, ">$varroot/num.txt");
    flock(TEMPLATE,2);
    print TEMPLATE "$totprod";
    close(TEMPLATE);

    print "Product is succesvol toegevoegd<br><a href=$inventoryurl?action=editprods>Terug naar Producten Beheer</a><br>";
    &preview_new;
    }

    sub editoldprod {
    use CGI;
    my $req = new CGI;
    $id=$req->param('id');
    if($req->param('Delete') eq "ON"){unlink("$dataroot/$id.txt");print "Product is succesvol verwijderd<br><a href=\"$inventoryurl?action=editprods\">Terug</a>";&footer;exit;}

    $features=$req->param('features');
    $features =~ s/\n/|/g;
    $features =~ s/\r//g;
    $maindesc=$req->param('maindesc');
    $maindesc =~ s/\n/<br>/g;
    $maindesc =~ s/\r//g;
    $shortdesc=$req->param('shortdesc');
    $shortdesc =~ s/\n/<br>/g;
    $shortdesc =~ s/\r//g;
    $ctime=time;
    $itemname=$req->param('itemname');
    $imageloc1=$req->param('imageloc1');
    $imageloc2=$req->param('imageloc');
    $imageloc3=$req->param('imageloc3');
    $imageloc4=$req->param('imageloc4');
    $imageloc5=$req->param('imageloc5');
    $imageloc6=$req->param('imageloc6');
    $price=$req->param('price');
    $partnum=$req->param('partnum');
    $categories=$req->param('categories');
    open(TEMPLATE, ">$dataroot/$id.txt");
    print TEMPLATE "$itemname\n";
    print TEMPLATE "$imageloc1\n";
    print TEMPLATE "$imageloc2\n";
    print TEMPLATE "$imageloc3\n";
    print TEMPLATE "$imageloc4\n";
    print TEMPLATE "$imageloc5\n";
    print TEMPLATE "$imageloc6\n";
    print TEMPLATE "$price\n";
    print TEMPLATE "$partnum\n";
    print TEMPLATE "$categories\n";
    print TEMPLATE "$ctime\n";
    print TEMPLATE "$maindesc\n";
    print TEMPLATE "$shortdesc\n";
    print TEMPLATE "$features|\n";
    close (TEMPLATE);

    print "Product werd succesvol gewijzigd<br><a href=\"$inventoryurl?action=editprods\">Terug</a><br>";
    &footer;
    exit;

    }

    sub preview_new {
    print "<font face=MS Sans Serif size=1>Overzicht producten:<br>";
    open (file, "$dataroot/$totprod.txt");
    flock(file,2);
    @file=<file>;
    close(file);
    $itemname=@file[0];
    $bigpic=@file[1];
    $smallpic=@file[2];
    $expic1=@file[3];
    $expic2=@file[4];
    $expic3=@file[5];
    $expic4=@file[6];
    $price=@file[7];
    $partnum=@file[8];
    $category=@file[9];
    $dates=@file[10];
    $maindesc=@file[11];
    $shortdesc=@file[12];
    $features=@file[13];

    @newfeatures=split(/\|/,$features);
    foreach $feature (@newfeatures) {

    $feature="".$feature."";
    $feature=~s/ //g;
    $feature=~s/\r//g;
    $feature=~s/\n\n//g;
    $featcount++;
    }

    @newfeatures[$featcount-1]="";
    open(TEMPLATE,"$temproot/mainlist.htm");
    @template = <TEMPLATE>;
    close(TEMPLATE);
    $bigpic="<img src=\"$imageshttp/$bigpic\">";
    $expic1="<img src=\"$imageshttp/$expic1\">";
    $expic2="<img src=\"$imageshttp/$expic2\">";
    $expic3="<img src=\"$imageshttp/$expic3\">";
    $expic4="<img src=\"$imageshttp/$expic4\">";
    foreach $curline (@template) {
    $curline=~ s/\[maindesc\]/$maindesc/g;
    $curline=~ s/\[price\]/$price/g;
    $curline=~ s/\[partnum\]/$partnum/g;
    $curline=~ s/\[bigpic\]/$bigpic/g;
    $curline=~ s/\[expic1\]/$expic1/g;
    $curline=~ s/\[expic2\]/$expic2/g;
    $curline=~ s/\[expic3\]/$expic3/g;
    $curline=~ s/\[expic4\]/$expic4/g;
    $curline=~ s/\[features\]/@newfeatures/g;
    $curline=~ s/\[itemname\]/$itemname/g;
    print $curline;
    }

    }
    1;
  2. #2
  3. vaginal warts are sooo 1973...
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Doom 2, sometime in 1995
    Posts
    73
    Rep Power
    15
    JESUS, JOSEPH AND MARY!

    That's got to be the longest posting of code I have ever seen on Devshed!

    Assuming you can get away with it on the server (and I can't see why not):

    Code:
    @filelist = ("filename1", "filename2", ... );
    chmod (0755, @filelist);
    As for:
    Code:
    my $file = $req->param('imageloc2'); 
    my $fileName = $file; 
    $fileName =~ s!^.*(\\|\/)!!; 
    $newmain = $fileName;
    
    $addtotprod++;
    if ($file ne "") {
    $prodname2="$totprod"."_small-"."$newmain";
    (open OUTFILE,">$dir/$prodname2");
    binmode(OUTFILE);
    while (my $bytesread = read($file, my $buffer, 1024)) { 
    print OUTFILE $buffer; 
    } 
    
    close(OUTFILE);
    }
    Looks to me like you could tidy up your code a bit by putting that code in a subroutine!

    Over to you Paul!

    dVdA
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    2
    Rep Power
    0

    DUh.. but uh..


    Thanx for your reply, but I'm a PHP prgrammer and really don't understand Perl. Though I'm able to change some pieces of code.
    So could you please tell me how to change it step by step.
    I got this script from antoher programmer months ago.
    Hope you can help me out.
  6. #4
  7. vaginal warts are sooo 1973...
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Doom 2, sometime in 1995
    Posts
    73
    Rep Power
    15

    aw, man...


    Man, you know that 'I just opened a can of worms' felling ... that's me right now.

    I'm in the same boat over PHP as you are with PERL. From what I've seen of PHP so far (SAMS, PHP in 21 days), I'm guessing you could re-write the code in PHP pretty easily. You could do it in a day.

    I like PHP because there are functions that are standard that would require external modules in PERL.

Similar Threads

  1. what is the difference...(ways of uploading)
    By Legendre in forum PHP Development
    Replies: 0
    Last Post: September 23rd, 2001, 04:57 PM
  2. strange .htpasswd uploading problem
    By thuynh7 in forum Apache Development
    Replies: 2
    Last Post: September 19th, 2001, 06:45 AM
  3. chmod() / permissions problem
    By munkfish in forum PHP Development
    Replies: 0
    Last Post: September 16th, 2001, 06:14 PM
  4. Backup files with file permissions
    By rroll99 in forum Dev Shed Lounge
    Replies: 1
    Last Post: July 19th, 2001, 06:01 PM
  5. help uploading php nuke
    By Dai in forum PHP Development
    Replies: 0
    Last Post: May 27th, 2001, 10:41 AM

IMN logo majestic logo threadwatch logo seochat tools logo