Please support our Python advertiser: Programming Forums
Views: 2367 | Replies: 7 | Solved
![]() |
•
•
Join Date: Jun 2005
Posts: 39
Reputation:
Rep Power: 4
Solved Threads: 0
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.
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.
•
•
Join Date: Jun 2005
Posts: 39
Reputation:
Rep Power: 4
Solved Threads: 0
ok, here ya go
and a sample of the text file lines
hope this helps...
by the way, if i dont use a variable but just print image="circle.giff"
it all works fine
thanks
#!/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
•
•
•
•
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
Awsome, care to share for the next person who comes by looking for the same help?
Firefox: no, its not the end all solution, it has its own issues and in time it will be just as insecure as IE, when its hit Firefox 6, if it makes it that far. Oh, and AOL pays for it, incase you didn't know.
Microsoft & Windows: If you hate it so much, move to linux, or bsd, or anything else, stop complaning and move on.
Good starting places: Gentoo Novell SUSE Fedora Core Apple
Microsoft & Windows: If you hate it so much, move to linux, or bsd, or anything else, stop complaning and move on.
Good starting places: Gentoo Novell SUSE Fedora Core Apple
•
•
Join Date: Jun 2005
Posts: 39
Reputation:
Rep Power: 4
Solved Threads: 0
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
then later....
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
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
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?
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?
May 'the Google' be with you!
•
•
Join Date: Jun 2005
Posts: 39
Reputation:
Rep Power: 4
Solved Threads: 0
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...
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...
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode