Post by merkat on Mar 21, 2015 7:10:25 GMT -5
Uploading photos has been a problem with Run Basic.
First it has to be at the root program, and not a RUNNED program.
You need some way of keeping track of your photos. That usually means maintaining a record for each photo. With this system you only need one photo ID for all your photos or data.
This system has always worked great for me, mainly because I run most of my stuff from a main menu. This makes it a RUNNED program and that's a problem.
This system solves several problems.
1. it can be run from a RUNNED program
2. It is one set of code that serves all your projects
2. You don't have to create a file to keep of each photo.
How it works.
Lets say you have a table called Equipment. You want to keep one or many photos of the equipment referenced by photoID.
The table may look something like this:
equipID varchar(10),
description varchar(30),
....
photoId varchar(20);
In the Equipment table you only need to create one photoID with something unique. For example the rowid. However when creating new records you don't have the rowid. So use maybe use something unique like time to nearest second:
t$ = time$()
hhmmss$ = left$(t$,2) + mid$(t$,4,2) + mid$(t$,7,2)
photoId$ = mid$(date$("yyyymmdd"),3)+hhmmss$
photoId$ = "X"+word$(photoId$+"_",1,"_") + "_"
This system looks for all photos that starts with that number. Therefore you can have as many photos as you like...
You need to create a project called "upload". This project takes care of uploads for all your systems.
You need to create a <iframe> in your code to run the photo program.
You pass information about your project, and directory to hold the uploaded photos, and how many photos are allowed.
First it has to be at the root program, and not a RUNNED program.
You need some way of keeping track of your photos. That usually means maintaining a record for each photo. With this system you only need one photo ID for all your photos or data.
This system has always worked great for me, mainly because I run most of my stuff from a main menu. This makes it a RUNNED program and that's a problem.
This system solves several problems.
1. it can be run from a RUNNED program
2. It is one set of code that serves all your projects
2. You don't have to create a file to keep of each photo.
How it works.
Lets say you have a table called Equipment. You want to keep one or many photos of the equipment referenced by photoID.
The table may look something like this:
equipID varchar(10),
description varchar(30),
....
photoId varchar(20);
In the Equipment table you only need to create one photoID with something unique. For example the rowid. However when creating new records you don't have the rowid. So use maybe use something unique like time to nearest second:
t$ = time$()
hhmmss$ = left$(t$,2) + mid$(t$,4,2) + mid$(t$,7,2)
photoId$ = mid$(date$("yyyymmdd"),3)+hhmmss$
photoId$ = "X"+word$(photoId$+"_",1,"_") + "_"
This system looks for all photos that starts with that number. Therefore you can have as many photos as you like...
You need to create a project called "upload". This project takes care of uploads for all your systems.
' ---------------------------------------------------
' upload
' This program uploads files from the client.
' It looks to the UrlKey$ to get information
' where to load and the name of the file to load.
' the file need not have a extension if it is not known.
' if it has no extension this program will add it to the file
' ---------------------------------------------------
WordWrap$ = "style='white-space: pre-wrap;";_
"white-space: -moz-pre-wrap;";_
"white-space: -pre-wrap;";_
"white-space: -o-pre-wrap;";_
"word-wrap: break-word'"
'print "------- upload Enviromental info ----------"
'print "UserInfo$ is: ";UserInfo$
'print "Platform is: ";Platform$
'print "UrlKeys$ is: ";UrlKeys$
'print "UserAddress$ is: ";UserAddress$
'print "EventKey$ is: ";EventKey$
'print "DefaultDir$ is: ";DefaultDir$
keysData$ = word$(UrlKeys$,02,"&")
keysProject$ = word$(keysData$,1,"|") ' run basic project
keysPhotoDir$ = word$(keysData$,2,"|") ' normally = photo
keysProg$ = word$(keysData$,3,"|") ' program who ran it
keysUserNum$ = word$(keysData$,4,"|") ' user Number
keysUserName$ = word$(keysData$,5,"|") ' user name
keysNumPhotos$ = word$(keysData$,6,"|") ' user Number string
keysPhotoId$ = word$(keysData$,7,"|") ' base photo ID + "_"
keysUserNum = val(keysUserNum$) ' user number
if keysNumPhotos$ = "*" then keysNumPhotos$ = "20"
keysNumPhotos = val(keysNumPhotos$) ' number of photos
if keysUserName$ = "|" then keysUserName$ = "None"
'print "UrlKeys$ ";UrlKeys$
'print "keysData$ ";keysData$
'print "keysProject$ ";keysProject$
'print "keysPhotoDir$ ";keysPhotoDir$
'print "keysProg$ ";keysProg$
'print "keysUserNum ";keysUserNum
'print "keysUserName$ ";keysUserName$
'print "keysNumPhotos$";keysNumPhotos$
'print "keysPhotoId$ ";keysPhotoId$
if right$(keysPhotoId$,1) <> "_" then
print "PHOTO ID ";keysPhotoId$;" must end in underscore '_'"
end
end if
if keysPhotoId$ = "" then
print "Please supply a photo ID"
end
end if
' =============================================================================================
' upload
' =============================================================================================
[upload]
bf$ = "<SPAN STYLE='font-family:Arial; font-weight:700; font-size:12pt'>"
bf1$ = "<SPAN STYLE='font-family:Arial; font-weight:700; font-size:10pt'>"
projectDir$ = keysProject$ + "_project"
if left$(Platform$,3) = "win" then
photoDir$ = DefaultDir$ + "\projects\" + projectDir$ + "\" + keysPhotoDir$ + "\"
photoPath$ = "../" + projectDir$ + "\" + keysPhotoDir$ + "\"
else
photoDir$ = DefaultDir$ + "/projects/" + projectDir$ + "/" + keysPhotoDir$ + "/"
photoPath$ = "../" + projectDir$ + "/" + keysPhotoDir$ + "/"
end if
' --------------------------------
' No browser cache
' --------------------------------
[doPhoto]
cls
head "<meta http-equiv='Cache-Control' content='no-cache, no-store, must-revalidate' />"
head "<meta http-equiv='Pragma' content='no-cache' />"
head "<meta http-equiv='Expires' content='0' />"
if errPhoto$ <> "" then
html bf1$;"<center><TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 width=90% BGCOLOR=lightGray><TR><TD>"
html errPhoto$
html "</TD></TR></TABLE>"
errPhoto$ = ""
end if
files #f, photoDir$ + keysPhotoId$ + "*"
if #f HASANSWER() <> 0 then np = #f rowcount() ' number of photos
w = (((np - 1) mod 5)+1) * 20
if np > 5 then w = 100
html bf$;"<center><TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 width=";w;"%>"
html "<TR align=center VALIGN=TOP>"
for i = 1 to np
#f nextfile$()
photoId$ = #f NAME$()
html "<TD bgcolor=lightGray>" '<B><FONT SIZE=1 FACE=Arial>";word$(photoId$,2,"_");"<br>"
button #del, "Delete", [delPhoto]
#del setkey(photoId$)
html "<br><IMG SRC='";photoPath$;photoId$;"' WIDTH=95%>"
html "</TD>"
if i mod 5 = 0 then html "</TR><TR align=center VALIGN=TOP>"
next i
html "</TR></TABLE>"
html bf$;"<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>"
html "<TR><TD align=center bgcolor=lightgray>Upload</TD></TR>"
html "<TR><TD ";WordWrap$;" >Photo ID:";keysPhotoId$;" |Allow:";keysNumPhotos$;" uploads |User:";keysUserNum;" ";keysUserName$;" |Project:";keysProject$;" ";keysPhotoDir$;"</TD></TR>"
html "<tr align=center><TD>"
upload ""; uploadId$
html "</TD></TR></TABLE>"
if uploadId$ = "" then
errPhoto$ = "Nothing to Upload"
goto [doPhoto]
end if
f$ = uploadId$
files #f, f$
if #f HASANSWER() = 0 then
errPhoto$ = "Photo: ";uploadId$;" not on file"
goto [doPhoto]
end if
' -------------------------------------
' load photo to photo directory
' -------------------------------------
OPEN uploadId$ FOR binary AS #f
filedata$ = input$(#f, LOF(#f))
CLOSE #f
x$ = strRep$(uploadId$,"_","-")
x$ = strRep$(uploadId$," ","")
x$ = strRep$(uploadId$,"'","")
photoId$ = keysPhotoId$ + x$
i = instr(keysPhotoId$,".")
' ------------------------------------
' delete file if already exists
' ------------------------------------
f$ = photoDir$+photoId$
files #f, f$
if #f HASANSWER() then kill f$
OPEN f$ FOR binary AS #f
PRINT #f, filedata$
CLOSE #f
goto [doPhoto]
' ---------------------------------
' delete photo
' ---------------------------------
[delPhoto]
kill photoDir$ + EventKey$
goto [doPhoto]
' --------------------------------
' string replace rep str with
' --------------------------------
FUNCTION strRep$(str$,rep$,with$)
ln = len(rep$)
ln1 = ln - 1
i = 1
while i <= len(str$)
if mid$(str$,i,ln) = rep$ then
strRep$ = strRep$ + with$
i = i + ln1
else
strRep$ = strRep$ + mid$(str$,i,1)
end if
i = i + 1
WEND
END FUNCTION
You need to create a <iframe> in your code to run the photo program.
You pass information about your project, and directory to hold the uploaded photos, and how many photos are allowed.
' --------------------------------------
' photo upload iframe setup
' --------------------------------------
keysProject$ = "elks" ' run basic project
keysPhotoDir$ = "photo" ' normally = photo
keysProg$ = "member" ' program who ran it(optional)
keysUserNum$ = loginMemNum$ ' user Number string(optional)
keysUserName$ = loginUserName$ ' key user name$(optional)
keysNumPhotos$ = "1" ' Number of allowable uploads * = infinity
if left$(acd$,3) <> "Add" then photoId$ = rowid$ + "_"
if photoId$ = "" then
t$ = time$()
hhmmss$ = left$(t$,2) + mid$(t$,4,2) + mid$(t$,7,2)
photoId$ = mid$(date$("yyyymmdd"),3)+hhmmss$
photoId$ = "X"+word$(photoId$+"_",1,"_") + "_"
end if
keysPhotoId$ = photoId$
'print keysPhotoId$
keysData$ = keysProject$ + "|" _
+ keysPhotoDir$ + "|" _
+ keysProg$ + "|" _
+ keysUserNum$ + "|" _
+ keysUserName$ + "|" _
+ keysNumPhotos$+ "|" _
+ keysPhotoId$ + "|"
html "<iframe "
html "src='http://www.kneware.com:8008/seaside/go/runbasicpersonal?app=upload&";keysData$;"&' width=100% height=500 >"
html "</iframe>"
wait