RSS Forums RSS
Please support our Python advertiser: Programming Forums
Views: 2365 | Replies: 7 | Solved
Reply
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

stuck in cgi image stuff

  #1  
Jun 14th, 2005
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2004
Posts: 2,548
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 178
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Solution Re: stuck in cgi image stuff

  #2  
Jun 14th, 2005
Interesting project, but I need a little more info. What does your code look like and your text file?
May 'the Google' be with you!
Reply With Quote  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: stuck in cgi image stuff

  #3  
Jun 14th, 2005
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>&nbsp;'
print '</big>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
print '&nbsp;&nbsp;<big>'+the_time+'</big>'
print '<br>'
print "1915 Cherokee <br>"
print "Dalhart, Tx 79022 <br>   333-5943&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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>&nbsp;&nbsp;&nbsp;&nbsp; "+lineList[NextStep]+"	"
	NextStep = NextStep + 1
	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
	print "<span style='font-weight: bold;'>Crop -</span>&nbsp;&nbsp;&nbsp;&nbsp; "+lineList[NextStep]+"	"
	NextStep = NextStep + 1
	print "<span style='font-weight: bold;'>GS -</span>&nbsp;&nbsp;&nbsp;&nbsp; "+lineList[NextStep]+"	"
	NextStep = NextStep + 1
	print '<br>'
	print '<br>'
	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
	print "<span style='font-weight: bold;'>Water -</span>&nbsp;&nbsp;&nbsp;&nbsp; "+lineList[NextStep]+"	"
	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
	print "<br>"
	print "<br>"
	NextStep = NextStep + 1
	print "<span style='font-weight: bold;'>Remarks -</span>&nbsp;&nbsp;&nbsp;&nbsp; "+lineList[NextStep]+"	"
	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
	NextStep = NextStep + 1
	print "<br>"
	print "<br>"
	print "<span style='font-weight: bold;'>Treatments -</span>&nbsp;&nbsp; "+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
Reply With Quote  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: stuck in cgi image stuff

  #4  
Jun 14th, 2005
nevermind, i found a work-around
Reply With Quote  
Join Date: Nov 2003
Location: Ohio
Posts: 778
Reputation: Zachery has a spectacular aura about Zachery has a spectacular aura about 
Rep Power: 8
Solved Threads: 20
Colleague
Zachery's Avatar
Zachery Zachery is offline Offline
The Geek Father

Re: stuck in cgi image stuff

  #5  
Jun 15th, 2005
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
Reply With Quote  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: stuck in cgi image stuff

  #6  
Jun 15th, 2005
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
Reply With Quote  
Join Date: Oct 2004
Posts: 2,548
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 178
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Solution Re: stuck in cgi image stuff

  #7  
Jun 15th, 2005
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?
May 'the Google' be with you!
Reply With Quote  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: stuck in cgi image stuff

  #8  
Jun 25th, 2005
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...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:25 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC