roberto68 Posted January 24, 2015 Share Posted January 24, 2015 I need to do a simple task user selects on Dropdown list - whether to take, or upload picture - and then whole from (the picture is the part of this form is send to php script so it can be saved to Database. so i google a bit but I'm still confused a little. so here's what I'm using //the javascript$("takePhoto").change(function() { // cchek - DDlist state change if(this.checked) { addPhotos(); } }function takeAction(){ $("#addPlace").submit(); }function addPhotos() { var takePicture = document.querySelector("#take-picture"), showPicture = document.querySelector("#show-picture"); if (takePicture && showPicture) { // Set events takePicture.onchange = function (event) { // Get a reference to the taken picture or chosen file var files = event.target.files, file; if (files && files.length > 0) { file = files[0]; try { // Get window.URL object var URL = window.URL || window.webkitURL; // Create ObjectURL var imgURL = URL.createObjectURL(file); // Set img src to ObjectURL showPicture.src = imgURL; // Revoke ObjectURL URL.revokeObjectURL(imgURL); } catch (e) { try { // Fallback if createObjectURL is not supported var fileReader = new FileReader(); fileReader.onload = function (event) { showPicture.src = event.target.result; }; fileReader.readAsDataURL(file); } catch (e) { // var error = document.querySelector("#error"); if (error) { error.innerHTML = "Neither createObjectURL or FileReader are supported"; } } } } }; }} //and finally the php.... $photo=$_POST['take-picture']; <form id="addPlace" action="set_coords.php" enctype="multipart/form-data"> <input type="text" name="location" id="location" visibility="hidden" /> Location: <input name="address" type="text" id="address" /><input type="hidden" name="total" id="total"/> Add Playground photos <select id="uploadType" ><option type="file" name="takePhoto" id="take-picture" accept="image/*"/> <option type="file" id="upload" onclick="upload();">Upload a photo</option> <!-- funckia upload - definovatv global js --> </select> <input type="checkbox" id="photo_boolean" /> </form> is that all I need? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 26, 2015 Share Posted January 26, 2015 I'm not sure what you're doing with the select list. Option elements do not have type attributes. If you want to do a file upload you need to use an input element with the type set to file, not an option element. In PHP, uploaded files will be in the $_FILES array, not $_POST. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now