Click to See Complete Forum and Search --> : Inputting images from a file into a form.
jonthomas83
02-28-2007, 04:56 AM
Hi guys,
Here's a strange one, I have already made a form that uploads images to a certain directory that also holds my database.
I now need to know how I go about, browsing for certain files within that directory from say an 'Insert Record' Form.
EG. I would like to input a new record from a web page, fill in all the details, and would like to choose one of the images from a folder, to input the filename of that image into the "Logo" filed in the input form.
example...
Airline: BMI Baby
URL: bmidotcom
Company Logo: bmi.gif <<<<< With a browse button next to the input text box that allows a user to select that image but only the actual file name.
Submit Button
Hope that makes sense.
PLEASE NOTE: I already have a form that uploads images to a directory, now I need a way of inputting the uploaded images into the database via a form on an 'insert record to database' page.
Many thanks for any suggestions
Jonathan
Sorehead
02-28-2007, 04:56 PM
You could read all the image files from the folder they are stored in and populate a option group with them, you wouldnt see the images but you would be able to select the file to be added to your db. One way maybe?...
jonthomas83
02-28-2007, 05:21 PM
Ok that sounds perfect and exactly what I need. I do not need to see the images themselves, I just wanna see their filenames (e.g. bmibaby.gif). But how do I populate an option group (you mean drop down menu right?) with a list of files in say the 'images' folder.
Also, when a seperate upload form is used to upload a new image to the folder, I would like the drop down list (as mentioned above) to automatically update and show the new image filename that has been uploaded.
Sorehead
02-28-2007, 05:33 PM
Is the seperate upload form on the same page or what?
Whats the process? does the image get uploaded first then the user is taken to another page?
If so then the "drop down" :) will be updated everytime a user loads the page.
Il give you an example once yu explain whats going on in a bit more details :)
jonthomas83
02-28-2007, 06:34 PM
Right yeah,
There's a page where the upload process takes place. And there's a page where a user can insert a new record into the database. HOWEVER, I've placed the upload page in an iframe on the same page as the 'insert record' form so that a user could either choose from existing images or could upload a new image to the directory and then iput it into the database that way.
I hope that makes sense!
Sorehead
02-28-2007, 06:49 PM
hmm, ok... well it would be sumthn like this you would need...
<select name="images">
<%
Dim fs,fo,x
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set fo=fs.GetFolder("D:\webs\mydomain.com\html\images") ' just change this to the server path for your folder
for each x in fo.files
%>
<option value="<%=x.Name%>"><%=x.Name%></option>
<%
next
set fo=nothing
set fs=nothing
%>
</select>
if a user used the iframe to upload a new image, then you will have to refresh the page so the script reads the contents of the folder again. Maybe give them a refresh button or sumthing.
I'll have a ponder on auto updating but im not a fan of iframes to be honest.
I'll let u know if i can think of anything.
jonthomas83
03-01-2007, 04:09 AM
Excellent mate, that sounds like a plan!
Hey I really appreciate your help on both topics by the way. I'll let you know if it works and if I get any problems I'll let you know. Thanks again.
P.S. I'm not a fan of iframes either but needed to find a way in which to put both forms on the same page like.
jonathan
jonthomas83
03-02-2007, 03:43 AM
Hi mate, that works a treat,
One more thing though. I have got it working in an 'insert record form' perfectly. However, I have an 'update record form' in which I want the default value in that drop down box to be the image that is already associated with that record.
For example in a simple text box input it would be...
value="<% =MyRS("DepLogo") %>" << pointing to the recordset with the record information (but you knew that already! hehe)
However, is there any way that I could get that sort of thing to work with the drop down box we made. So that the user doesn't have to change the default image if it's correct, but will have the choice to use the other images in the file if they wish to, using the drop down menu. (For it to be effective it needs to be implemented on the drop down box).
Also, any news on an automatic refresh code that I could place somewhere when I upload a new image to the folder like we were discussing before?
Many, many thanks
Jonathan
P.S. You've been an awesome help and I really appreciate it. It's one hell of a good piece of work because of your help! (Even if I say so myself! lol)
Sorehead
03-02-2007, 05:43 AM
Sumthn like this would select the image as the default
<select name="images">
<%
Dim fs,fo,x, defImage
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set fo=fs.GetFolder("D:\webs\mydomain.com\html\images") ' just change this to the server path for your folder
for each x in fo.files
if MyRS("DepLogo") = x.Name then
defImage = "selected"
else
defImage = ""
end if
%>
<option value="<%=x.Name%>" selected="<%=defImage%>"><%=x.Name%></option>
<%
next
set fo=nothing
set fs=nothing
%>
</select>
Still thinking about the auto refresh, maybe have to be javascript to deal with the iframes....:confused: I'll continue to ponder..
jonthomas83
03-02-2007, 06:19 AM
It just seems to be setting the last image in the drop-down list to the default mate.
Sorehead
03-02-2007, 06:25 AM
<select name="images">
<%
Dim fs,fo,x, defImage
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set fo=fs.GetFolder("D:\webs\mydomain.com\html\images") ' just change this to the server path for your folder
for each x in fo.files
if MyRS("DepLogo") = x.Name then
defImage = "selected='selected'"
else
defImage = ""
end if
%>
<option value="<%=x.Name%>" <%=defImage%>><%=x.Name%></option>
<%
next
set fo=nothing
set fs=nothing
%>
</select>
Try That
jonthomas83
03-02-2007, 06:41 AM
Mate you are a LEGEND!
Thank you so much, I owe you so many pints it's unbelievable. It must make your day to make someone so happy as I am right now!
You wouldn't believe!
YEY YEY YEY YEY YEY!!!!! my god I'm chuffed!
Thank you so much, I know it aitnt gonna happen but maybe one day I'll be able to help you out with code one day! Who knows.
I think you just got me a 1st buddy! (let's not count our chickens though! hehe)
I'm so pleased I'm rambling about nothing! sorry!
Sorehead
03-02-2007, 06:44 AM
lol, Hey no prbs mate, glad I could help. :D
jonthomas83
03-02-2007, 06:53 AM
You've not just helped mate, you've saved my degree! Thank you very much! :)