I am uploading files, in such a way the user does not need to hit the button 'Upload' after selecting the file. It works fine but I also need to send an extra parameter and, since I'm not into Javascript at all, I can not figure out how to send it.
The html:
<form enctype="multipart/form-data" target="_blank" name="send_img" id="send_img" method="post" action="img_upload.php">
<input type="hidden" id="group_id" name="group_id" value="2" />
<input type="file" class="hide" id="uploaded_file" name="uploaded_file" onChange="Handlechange();"/>
<button type="submit" id="btn">Subir fotos!</button>
</form>
<div onclick="HandleBrowseClick();" id="fakeBrowse" >Load a picture</div>
The script:
<script language="JavaScript" type="text/javascript">
function HandleBrowseClick()
{
var fileinput = document.getElementById("uploaded_file");
fileinput.click();
}
function Handlechange()
{
var fileinput = document.getElementById("uploaded_file");
var textinput = document.getElementById("filename");
textinput.value = fileinput.value;
}
</script>
I have no clue how to send the group_id variable (which I have in a php variable, so it can be echoed anywhere, even in the script). I tried many ways with no luck. So how can that variable to be passed and gotten in img_upload.php? I thought that:
var group_id = document.getElementById("group_id").value;
would make it but I was wrong :-/
What I also find interesting is that if I modify the form tag to action="img_upload.php?group_id=2", I can not get the parameter later in that file by doing $_GET['group_id'];
In img_upload.php I am taking this other variable and inserting it into a database. So it would be really cool if I can get that variable in such a way I can get it into a php variable (I tried to be as clear as possible in this last line).
I would also add what I get in Chrome Developer Tool:
Request Payload
------WebKitFormBoundarydOdbB5IQ8RbA8CRR
Content-Disposition: form-data; name="uploaded_file[]"; filename="photo-5.JPG"
Content-Type: image/jpeg
------WebKitFormBoundarydOdbB5IQ8RbA8CRR--
That's what makes me think the problem is in the data sending script
group_idfrom the hidden input?