-
Python (
http://www.daniweb.com/forums/forum114.html)
| nephish | Jun 14th, 2005 1:44 am | |
| stuck in cgi image stuff i have an html form with a drop-down list that lists a bunch of images.
how can i get my cgi script to load the image ?
i have imported cgi and os
text entered from a form and read from a file do ok, but i cant seem to get it to load an image.
the form writes all of the entries as lines in a .txt file
this file is selected later,
all the lines are read,
and based on the first line of the text file determines the name of the .gif image to load.
is there a way to do this, i think i am getting all the ' and '' stuff confused.
thanks. |
| vegaseat | Jun 14th, 2005 9:53 am | |
| Re: stuck in cgi image stuff Interesting project, but I need a little more info. What does your code look like and your text file? |
| nephish | Jun 14th, 2005 12:57 pm | |
| Re: stuck in cgi image stuff ok, here ya go
#!/usr/bin/python
import os
import cgi
import cgitb; cgitb.enable()
from time import gmtime, strftime
the_time = strftime("%A, %B %d, %Y") #Get a TimeStamp
#This script takes data from ViewRecords.py and opens and views the
#Selected text file
#some bug some where
form = cgi.FieldStorage()
DataRecord = form['DataTime'].value
Customer = form['CustName'].value
# Set up the html stuff
reshtml = """Content-Type: text/html\n
<html>
<head><title>Customer Data</title></head>
<body>
"""
print reshtml
print '<big><span style="font-weight: bold;">Watkins Crop Consulting</span> '
print '</big> '
print ' <big>'+the_time+'</big>'
print '<br>'
print "1915 Cherokee <br>"
print "Dalhart, Tx 79022 <br> 333-5943 <H2>"+Customer+"</H2>"
fileHandle = open("/var/www/stretch/web_root/SidCrops/"+Customer+"/"+DataRecord, "r")
lineList = fileHandle.readlines()
fileHandle.close()
Line_Iters = len(lineList)/7 #number of lines in the file divided by 7 (how many fields there are)
Iterations = 0 #represents the number of times the following while loop will run
NextStep = 0 #Increments to the next line of the file
while Iterations < Line_Iters:
print '<meta'
print 'content="text/html; charset=ISO-8859-1" http-equiv="content-type">'
print '<title></title>'
print '</head>'
print '<body>'
print '<table style="text-align: left; width: 100%;"'
print 'border="0" cellpadding="0" cellspacing="0">'
print '<tbody>'
print '<tr>'
print '<td><img'
print 'style="width: 150px; height: 150px;" alt="circle"'
print 'src="http://stretchweb.org/"'+lineList[NextStep]+".gif"+"></td>'
print '<td>'
NextStep = NextStep + 1
print "<span style='font-weight: bold;'>Field -</span> "+lineList[NextStep]+" "
NextStep = NextStep + 1
print ' '
print "<span style='font-weight: bold;'>Crop -</span> "+lineList[NextStep]+" "
NextStep = NextStep + 1
print "<span style='font-weight: bold;'>GS -</span> "+lineList[NextStep]+" "
NextStep = NextStep + 1
print '<br>'
print '<br>'
print ' '
print "<span style='font-weight: bold;'>Water -</span> "+lineList[NextStep]+" "
print ' '
print "<br>"
print "<br>"
NextStep = NextStep + 1
print "<span style='font-weight: bold;'>Remarks -</span> "+lineList[NextStep]+" "
print ' '
NextStep = NextStep + 1
print "<br>"
print "<br>"
print "<span style='font-weight: bold;'>Treatments -</span> "+lineList[NextStep]+" "
print "<br>"
NextStep = NextStep + 1
Iterations = Iterations + 1
print "<br>"
print "<br>"
print '</td>'
print '</tr>'
print '</tbody>'
print '</table>'
print '<br>'
print '<br>'
print '<br>'
print '<br>'
print "<br>"
print "</body>"
print "</html>"
and a sample of the text file lines
Quote: circle1.gif
line
of
text
will
always
be a factor of seven
circle2.giff
because
the .py file
that writes
the text from the form
writes seven lines at
a time |
hope this helps...
by the way, if i dont use a variable but just print image="circle.giff"
it all works fine
thanks |
| nephish | Jun 14th, 2005 7:26 pm | |
| Re: stuck in cgi image stuff nevermind, i found a work-around |
| Zachery | Jun 15th, 2005 5:40 am | |
| Re: stuck in cgi image stuff Awsome, care to share for the next person who comes by looking for the same help? :) |
| nephish | Jun 15th, 2005 8:34 am | |
| Re: stuck in cgi image stuff um.. sure.
instead of having the script write just the name of the image file to load , i had it write the whole html line when the image is selected like this
image = form['image'].value
then later....
OutFile.write('src="http://stretchweb.org/'+image+'"></td>\n')
the script that reads the lines, just does this...
print image...
and it worked !
if you need more details or want to see the whole script, let me know |
| vegaseat | Jun 15th, 2005 11:08 am | |
| Re: stuck in cgi image stuff Gee nephish,
I am still scratching my head trying to figure out why the first version did not work and you come up with a working alternate. Great job!!!
By the way, you are right this line is a ""/' nightmare, my editor flags it down as an error, wants a " at the end ...
[php]print 'src="http://stretchweb.org/"'+lineList[NextStep]+".gif"+"></td>'
[/php]
Maybe you can triple quote the whole spiel.
Also, the indents in the while loop are not consistent, are you mixing up tabs and spaces? I always use spaces since tabs are not set the same with every computer.
Are you using .gif or .giff? |
| nephish | Jun 25th, 2005 7:24 am | |
| Re: stuck in cgi image stuff oh, i am using a gif.
and it works now, but here is what i had to do.
i have the script that writes the line to the text file write
print 'src="http://stretchweb.org/"'+lineList[NextStep]+".gif"+">
and then the script that prints the image just reads this line from a text file
and prints it
print line[1]
in the middle of it printing other html stuff.
gee whiz, it works, but ...... man......
thanks for your help.
not a very clean way to do it.. but it works right now.
i think very much that the problem i was having was in the line up
of quotes...because the error i kept getting was about not ending script headers... |
| All times are GMT -4. The time now is 8:32 am. | |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC