Solved

Upload Image file radio button option

Posted on 2011-02-12
9
519 Views
Last Modified: 2012-05-11
Hello All,

I have an upload field in a form that allows the user to upload a photo. If the user does not have a photo, I'd like them to be able to select an image, located on mySite by clicking a radio button.

Basically what I want it to do is to give the user the option to select an image (on the mySite server) by clicking one of the radio buttons, if they don't have an image (file) to upload.

The function I am looking for is to load the URL (i.e. http://mySite.com/images/corp-man1.jpg) into the  "photo_img"  field when the user selects one of the radio buttons.

The upload code itself works fine. I've added radio buttons. I just need a way to substitute the "photo_img" value using the radio buttons.

Here's a code snippet. I'm assuming there will be some sort of 'IF' statement and variables.

Thank you for taking a look at this.
<p><label for="photo_img">Upload Photo:</label><br/>
	<input type="file" name="photo_img" id="photo_img">
	<input type="submit" value="Clear" onclick="javascript: clearFileInputField('photo_img'); return false;"/>
</p><br />

	<table width="200" border="0" cellpadding="0" cellspacing="0">
				<tr>
							<td width="110" align="center" valign="middle" bgcolor="#FFFFFF"><label>
										<input type="radio" name="PhotoSubM" value="http://mySite.com/images/corp-man1.jpg" id="PhotoSubM_0" />
										Man1</label></td>
				</tr>
				<tr>
							<td align="center" valign="middle" bgcolor="#FFFFFF"><label>
										<input type="radio" name="PhotoSubM" value="http://mySite.com/images/corp-man2.jpg" id="PhotoSubM_1" />
										Man2</label></td>
				</tr>
				<tr>
							<td align="center" valign="middle" bgcolor="#FFFFFF"><label>
										<input type="radio" name="PhotoSubM" value="http://mySite.com/images/corp-man3.jpg" id="PhotoSubM_2" />
										Man3</label></td>
				</tr>
				<tr>
							<td align="center" valign="middle" bgcolor="#FFFFFF"><label>
										<input type="radio" name="PhotoSubM" value="http://mySite.com/images/corp-man4.jpg" id="PhotoSubM_3" />
										Man4</label></td>
				</tr>
				<tr>
							<td align="center" valign="middle" bgcolor="#FFFFFF"><label>
										<input type="radio" name="PhotoSubM" value="http://mySite.com/images/corp-man5.jpg" id="PhotoSubM_4" />
										Man5</label></td>
				</tr>
	</table>

Open in new window

0
Comment
Question by:Champ007
  • 4
  • 3
9 Comments
 
LVL 10

Accepted Solution

by:
cyberstalker earned 250 total points
ID: 34881691
That is not possible. You cannot modify the value of a file type input control with javascript. The browser will not allow it. Besides, the input file is to upload a local file, which is what you do not want to do in this case.

What I would do, is check in the receiving PHP script if an upload file is provided, and use that, and if not see what option was selected and use that instead.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34882917
If you do not have experience programming in PHP, you might find that this book is helpful.
http://www.sitepoint.com/books/phpmysql4/

In order to give you any concrete help with this question we will need to see all of the HTML form script and all of the PHP action script.  Please post those in the code snipppet so we can see what you have tried already.  Once we have that, we will be able to suggest solutions that are more on target than just a teaching example.  Thanks.
0
 

Author Comment

by:Champ007
ID: 34893509
cyberstalker - If PHP is the only way to go, can you provide a link or 2 that will provide a teaching example that I can follow.

Thanks
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 34895970
The Sitepoint book has excellent teaching examples on exactly this topic - that is why I recommended it.  But it sounds like you are almost there already from this, "The upload code itself works fine. I've added radio buttons."  Please post the complete HTML and PHP action script that you are using now, and we can show you how to make the conditional tests that would let you distinguish between an uploaded file and an activated radio button.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Champ007
ID: 34910047
I submitted a delete request for question: http://www.experts-exchange.com/Q_26817561.html.
There is a pending objection to deleting this topic. This post is the open question I am seeking a solution. Currently there are no satifactory solutions. An author's comment  to cyberstalker is pending a reply.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34910806
"Currently there are no satifactory [sic] solutions."

You will need to work with us a little bit here (and you may find that you need to hire a professional developer, if you do not have the knowledge, skills and abilities to write code).  The strategy you will want to use goes something like this.

In the action script that processes the form input, you will look for the $_FILES array to see if an image was uploaded.  You will test the "error" indicators, and if there are no errors and a valid file was present, you will use that image.  If that is not the case, then you will look in the $_POST array to see if a radio button named $_POST["PhotoSubM"] is set.  You will want to be very careful about using the value in this field, since you're going to be transmitting a URL in the field.  Nice people will not tamper with the URL.  Hackers will have a field day destroying your site and attacking all the browsers of visitors that come to your site if you do not sanitize this input.

Please post the entire HTML form script and PHP action script as you have them now, thanks.  Partial scripts are not really useful in this case.
0
 

Author Closing Comment

by:Champ007
ID: 35041106
No solution provided.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35046549
An exact and detailed explanation of the solution was provided three weeks ago at ID:34910806, yet you gave a bad grade.  I do not understand.

Why did you refuse repeated requests to post your code?  Why did you mark the response down to a "B"?  Can you think of any reason we would want to try to help you in the future?  If so, please post those reasons.  Thanks, ~Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now