473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
Aug 9 '07 #1
12 2405
KevinADC
4,059 Expert 2GB
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....
Aug 10 '07 #2
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.

Expand|Select|Wrap|Line Numbers
  1. <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>
  2. HTML
  3.  
  4. open (BASE, $dbp) || do {&no_open;};
  5. @sorted = sort(<BASE>);
  6. foreach $pair (@sorted)
  7. {
  8. @show = split(/,/, $pair);
  9. $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>";
  10. print "$showpic";}
  11. close(BASE);
  12.  
  13. print <<"HTML";
  14. </tr></table></td></form></tr>
any help would be appreciated.

thanks
Aug 10 '07 #3
KevinADC
4,059 Expert 2GB
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.
Aug 11 '07 #4
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
Aug 11 '07 #5
KevinADC
4,059 Expert 2GB
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.
Aug 11 '07 #6
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:

Expand|Select|Wrap|Line Numbers
  1. <table cellpadding='2' border='0' width="729" cellspacing='2' bgcolor='#FFFFFF'>
  2. HTML
  3.  
  4. open (BASE, $dbp) || do {&no_open;};
  5. @sorted = sort(<BASE>);
  6. foreach $pair (@sorted)
  7. {
  8. @show = split(/,/, $pair);
  9. $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>";
  10. print "$showpic";}
  11. close(BASE);
  12. print <<"HTML";
  13. </table>

Any ideas?
thanks
Aug 13 '07 #7
KevinADC
4,059 Expert 2GB
well, it seems obvious why you are getting the same image repeated, you repeatedly use $show[0] in the same loop iteration.
Aug 13 '07 #8
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
Aug 13 '07 #9
KevinADC
4,059 Expert 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. my $td_start =  qq{<td bgcolor='beige' width='50' valign='top' align='center'><INPUT TYPE='radio' NAME='photo' value='$photopath};
  2. my $td_end   =  qq{' border='0' width='50' height='50'></td>};
  3. my $showpic  =   q{<table cellpadding='2' border='0' width="729" cellspacing='2' bgcolor='#FFFFFF'><tr>};
  4. open (BASE, $dbp) or no_open();
  5. my @sorted = sort(<BASE>);
  6. close BASE;
  7. my $i = 0;
  8. foreach my $pair (@sorted){
  9.    $i++;
  10.    my @show = split(/,/, $pair);
  11.    $showpic .= qq{$td_start$show[0]>&nbsp;<img src='$photopath$show[0]$td_end};
  12.    $showpic .= '</tr><tr>'  if $i == 14; 
  13. }
  14. $showpic .= '</tr></table>';
  15. print $showpic;
  16.  
Aug 13 '07 #10
Ok, that's great.....except 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
Aug 13 '07 #11
KevinADC
4,059 Expert 2GB
actually that was a bit of an omission on my part. You reset the flag to zero after it reaches the desired count:

Expand|Select|Wrap|Line Numbers
  1. my $i = 0;
  2. foreach my $pair (@sorted){
  3.    $i++;
  4.    my @show = split(/,/, $pair);
  5.    $showpic .= qq{$td_start$show[0]>&nbsp;<img src='$photopath$show[0]$td_end};
  6.    if ($i == 5) {
  7.       $showpic .= '</tr><tr>';
  8.       $i = 0; # <-- reset the flag
  9.    }
  10. }
Aug 14 '07 #12
thank you again!

Paul
Aug 14 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
by: SEMIH DEMIR | last post by:
Sitelerden birinde verilen yabancı kaynakli bir scriptti duzenledim yanlız birseyin içinden bir turlu cıkamadım işin aslı ilk defa persistin upload componentini kullanacam yanlız suanki haliyle...
4
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
3
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
1
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
7
by: mishrarajesh44 | last post by:
hii all Truly telling i hav got this code from net & i am finding error while running the code below.. code:- <?php $idir = "photo/"; // Path To Images Directory $tdir =...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.