Solved

Upload Image file radio button option

Posted on 2011-02-12
9
518 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Champ007
Comment Utility
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
Comment Utility
"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
Comment Utility
No solution provided.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

9 Experts available now in Live!

Get 1:1 Help Now