Hi, how can you upload more then one file at a time.
I am able to upload one file at a time.
well, in the html I don't have the input fields as an array.
I have javascript to count them and right next to their name I would add their numbers.
Then I submit them. Now I have no clue on the php side how to do multiple files.
I do know that I need to do a for or a for each loop but I find examples only showing how to do this with input names as arrays.
I don't have them in arrays but I count them and give them a number next to their names.
so how would I do this if I didn't make the names in html arrays but actually added numbers to the name.
for example lets say the name of input is images.
in html/php it be images[]
but I have it like this images1 , images2, images3 etc.
how can I do the for loop thru them?? I want to first count what been uploaded. So I know what the max we have so I can stop the loop when we loop thru all them.
any ideas?
I want to do this without using HTML arrays.
7 Replies - 1290 Views - Last Post: 22 November 2011 - 12:34 AM
#1
PHP how to upload more the one file at a time without using arrays in
Posted 20 November 2011 - 09:37 PM
Replies To: PHP how to upload more the one file at a time without using arrays in
#2
Re: PHP how to upload more the one file at a time without using arrays in
Posted 20 November 2011 - 10:15 PM
Put multiple <input type="file"> elements in your form. All of them are uploaded and you can access them using the $_FILES array. Check out that array at PHP.net for more information. It will explain how you can do multiple files.
#3
Re: PHP how to upload more the one file at a time without using arrays in
Posted 20 November 2011 - 10:27 PM
Martyr2, on 20 November 2011 - 11:15 PM, said:
Put multiple <input type="file"> elements in your form. All of them are uploaded and you can access them using the $_FILES array. Check out that array at PHP.net for more information. It will explain how you can do multiple files.
well I dynamically add the inputs inside a div.
I don't have them in array form.
I have input named like image1, image2, image3, image4.
I don't have it in an array form. Would this matter or would I still do it the same way as if I did it by using html arrays?
#4
Re: PHP how to upload more the one file at a time without using arrays in
Posted 20 November 2011 - 11:16 PM
that way you would have to fetch them by each single name.
believe me, arrays are easier to work with.
believe me, arrays are easier to work with.
#5
Re: PHP how to upload more the one file at a time without using arrays in
Posted 20 November 2011 - 11:21 PM
Dormilich, on 21 November 2011 - 12:16 AM, said:
that way you would have to fetch them by each single name.
believe me, arrays are easier to work with.
believe me, arrays are easier to work with.
ya but then the problem would be how would I be able to remove them if the user clicks the delete button. If I use an array then when you hit the delete button it will delete all inputs at the same time. Instead of just deleting just that one.
#6
Re: PHP how to upload more the one file at a time without using arrays in
Posted 20 November 2011 - 11:45 PM
then your way of accessing the element to delete is faulty.
let’s say you have the delete button and the input in a list
by using jQuery deleting becomes as easy as
and in plain JS it ain’t that much more complicated:
let’s say you have the delete button and the input in a list
<li> <input type="file" name="images[]"> <button type="button">delete</button> </li>
by using jQuery deleting becomes as easy as
$("li button").click(function(evt) {
$(this).parent().remove();
});
and in plain JS it ain’t that much more complicated:
function delete(evt)
{
var p = this.parentNode;
p.parentNode.removeChild(p);
}
(function(){
var b = document.querySelectorAll("li button");
for (var l = b.length; l--;)/> {
b[l].addEventListener("click", delete, true); // or the appropriate cross-browser code
}
})();
This post has been edited by Dormilich: 20 November 2011 - 11:46 PM
#7
Re: PHP how to upload more the one file at a time without using arrays in
Posted 21 November 2011 - 11:25 PM
Dormilich, on 21 November 2011 - 12:45 AM, said:
then your way of accessing the element to delete is faulty.
let’s say you have the delete button and the input in a list
by using jQuery deleting becomes as easy as
and in plain JS it ain’t that much more complicated:
let’s say you have the delete button and the input in a list
<li> <input type="file" name="images[]"> <button type="button">delete</button> </li>
by using jQuery deleting becomes as easy as
$("li button").click(function(evt) {
$(this).parent().remove();
});
and in plain JS it ain’t that much more complicated:
function delete(evt)
{
var p = this.parentNode;
p.parentNode.removeChild(p);
}
(function(){
var b = document.querySelectorAll("li button");
for (var l = b.length; l--;)/> {
b[l].addEventListener("click", delete, true); // or the appropriate cross-browser code
}
})();
but wouldn't that delete the whole list?
I want the user to be able to delete each input file they added but not all at one time.
#8
Re: PHP how to upload more the one file at a time without using arrays in
Posted 22 November 2011 - 12:34 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|