Upload image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deppeler
    New Member
    • Jul 2007
    • 40

    Upload image

    I have a simple flat file db, a toy library
    When users add an entry they can choose which 'kit' it belongs to, include a name, description, ID number, etc.
    Is it possible to add an image at well.
    The only way I can think to do it is to run a seperate script (upload) from within the main script.
    The problem with that is that the location for the image file doesn't get written to the db, at least I don't know how to do that from a seperate script.
    Is there an easy way to do this without resorting to a seperate script?

    thanks
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Well, you will need to upload the file (or have the script point to the url of an image on the internet) so there has to be some file upload capability, either in the main script, or a module or a seperate script. How you do it depends on what is best for your situation. You can read the "how to upload files" article in the perl articles archive:

    how to upload files....

    Comment

    • deppeler
      New Member
      • Jul 2007
      • 40

      #3
      thanks for the info.
      I decided to go with the seperate upload script.

      I have one issue.
      I can get the script to write the uploaded images to the DB and display the result in cells in a table.
      My table width is '729' px how do I format it so when displayed, if I have say 20 images they will 'wrap' into the next row instead of continuing across the page.
      Here is a snippert of code I am using now.

      Code:
      <tr><FORM ACTION='/cgi-bin/toy/dbeditphoto.cgi' METHOD='POST'><INPUT TYPE='hidden' NAME='addp'><td bgcolor='#FFFFFF' colspan='6'><table cellpadding='2' border='1' width="729" cellspacing='0'><tr>
      HTML
      
      open (BASE, $dbp) || do {&no_open;};
      @sorted = sort(<BASE>);
      foreach $pair (@sorted)
      {
      @show = split(/,/, $pair);
      $showpic = "<td bgcolor='#FFFFFF' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td>";
      print "$showpic";}
      close(BASE);
      
      print <<"HTML";
      </tr></table></td></form></tr>
      any help would be appreciated.

      thanks

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        This is really an html question now. All I can suggest is reading up on html, which is pretty simple stuff really, and try out a few things to get the formatting how you want it.

        Comment

        • deppeler
          New Member
          • Jul 2007
          • 40

          #5
          I do know html but this is a little different because the number of images is always changing and to get it to format therefore wrap at 729px within the perl script is not easy.
          I just thought I had come across some perl code at some time that would do this but I guess not.

          thanks
          anyway
          Paul

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            If your table is 729 wide, and each td cell is 50 wide, 20 images is 1000. The most images you can get side by side is 14 (700) with that width. So count 14 cells and add a </tr><tr> sequence as needed.

            Comment

            • deppeler
              New Member
              • Jul 2007
              • 40

              #7
              I tried that but what I get is the correct table width but each row contains just one image repeated across the 12 cells as per below.




              Again here is a snippet of code I am using:

              Code:
              <table cellpadding='2' border='0' width="729" cellspacing='2' bgcolor='#FFFFFF'>
              HTML
              
              open (BASE, $dbp) || do {&no_open;};
              @sorted = sort(<BASE>);
              foreach $pair (@sorted)
              {
              @show = split(/,/, $pair);
              $showpic = "<tr><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td><td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath$show[0]'>&nbsp;<img src='$photopath$show[0]' border='0' width='50' height='50'></td></tr>";
              print "$showpic";}
              close(BASE);
              print <<"HTML";
              </table>

              Any ideas?
              thanks

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                well, it seems obvious why you are getting the same image repeated, you repeatedly use $show[0] in the same loop iteration.

                Comment

                • deppeler
                  New Member
                  • Jul 2007
                  • 40

                  #9
                  Ok, as you can see I am getting the correct image on each row.

                  Can you give me a clue as to how I get this right.

                  thanks
                  Paul

                  Comment

                  • KevinADC
                    Recognized Expert Specialist
                    • Jan 2007
                    • 4092

                    #10
                    What you really need to do is stop now and start using "strict" and "warnings" in all your perl scripts. It will be a little difficult at first but can save you big problems later. Making some guesses, fiddle around with this code:

                    Code:
                    my $td_start =  qq{<td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath};
                    my $td_end   =  qq{' border='0' width='50' height='50'></td>};
                    my $showpic  =   q{<table cellpadding='2' border='0' width="729" cellspacing='2' bgcolor='#FFFFFF'><tr>};
                    open (BASE, $dbp) or no_open();
                    my @sorted = sort(<BASE>);
                    close BASE;
                    my $i = 0;
                    foreach my $pair (@sorted){
                       $i++;
                       my @show = split(/,/, $pair);
                       $showpic .= qq{$td_start$show[0]>&nbsp;<img src='$photopath$show[0]$td_end};
                       $showpic .= '</tr><tr>'  if $i == 14; 
                    }
                    $showpic .= '</tr></table>';
                    print $showpic;

                    Comment

                    • deppeler
                      New Member
                      • Jul 2007
                      • 40

                      #11
                      Ok, that's great.....excep t how do I get it to show 5 images per row, I changed $i == 14; to 5 but that didn't work the top row showed 5 and the next row ALL the rest of the images in the DB.

                      thanks
                      Paul

                      Comment

                      • KevinADC
                        Recognized Expert Specialist
                        • Jan 2007
                        • 4092

                        #12
                        actually that was a bit of an omission on my part. You reset the flag to zero after it reaches the desired count:

                        Code:
                        my $i = 0;
                        foreach my $pair (@sorted){
                           $i++;
                           my @show = split(/,/, $pair);
                           $showpic .= qq{$td_start$show[0]>&nbsp;<img src='$photopath$show[0]$td_end};
                           if ($i == 5) {
                              $showpic .= '</tr><tr>';
                              $i = 0; # <-- reset the flag
                           }
                        }

                        Comment

                        • deppeler
                          New Member
                          • Jul 2007
                          • 40

                          #13
                          thank you again!

                          Paul

                          Comment

                          Working...