Hello there,
This is my form:
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="text" name="nume" id="nume"/>
<select name="an" id="an" >
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2010">2016</option>
<option value="2011">2017</option>
<option value="2012">2018</option>
<option value="2013">2019</option>
<option value="2014">2020</option>
<option value="2015">2021</option>
</select>
<input type="file" name="images" id="images" multiple />
<button type="submit" id="btn">Upload Files!</button>
</form>
<script src="upload.js"></script>
here is upload.js file:
(function () {
var input = document.getElementById("images"),
inputan = document.getElementById("an"),
inputnume = document.getElementById("nume"),
formdata = false;
function showUploadedItem (source) {
var list = document.getElementById("image-list"),
li = document.createElement("li"),
img = document.createElement("img");
img.src = source;
li.appendChild(img);
list.appendChild(li);
}
if (window.FormData) {
formdata = new FormData();
document.getElementById("btn").style.display = "none";
}
input.addEventListener("change", function (evt) {
document.getElementById("response").innerHTML = "Uploading . . ."
var i = 0, len = this.files.length, img, reader, file;
for ( ; i < len; i++ ) {
file = this.files[i];
if (!!file.type.match(/image.*/)) {
if ( window.FileReader ) {
reader = new FileReader();
reader.onloadend = function (e) {
showUploadedItem(e.target.result, file.fileName);
};
reader.readAsDataURL(file);
}
if (formdata) {
formdata.append("images[]", file);
}
}
}
if (formdata) {
$.ajax({
url: "upload.php",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function (res) {
document.getElementById("response").innerHTML = res;
}
});
}
}, false);
}());
and here is my upload.php file:
<?php
$an = $_POST['an'];
$nume = $_REQUEST['nume'];
foreach ($_FILES["images"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
move_uploaded_file( $_FILES["images"]["tmp_name"][$key], "../speed_west/imagini/$an/$nume/" . $_FILES['images']['name'][$key]);
}
}
echo "<h2>succes...</h2>";
so....in upload.php images it's work just fine but i want to collect values " 'an' and 'nume' " from form and put them in my path ("../speed_west/imagini/$an/$nume/")
Hope so that you understand what i try to do!
Thanks in advances!