?
Solved

Upload Image file radio button option

Posted on 2011-02-12
9
Medium Priority
?
527 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 10

Accepted Solution

by:
cyberstalker earned 750 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 111

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 750 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
 

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 111

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 111

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 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