Jump to content

[SOLVED] a form with dynamic file inputs and PHP


Godspeed! phi

Recommended Posts

Hello everyone. I'm trying to do something, and I'm not sure if it is at all possible.

 

I created an HTML form for the user to write a blog post. I am allowing him to post images with the post, and I don't want a limit on the number of pictures. Here's how it works so far:

 

1) The user clicks on a button for 'Add an Image'

2) Javascript sets the button's style.display is set to 'none' (it's hidden)

3) Javascript creates a file input with a unique name, and 'next' button

4) The user uses the file input and selects an image and clicks 'next'

5) The newly created file input's style.display is set to 'none' (it's hidden)

6) The button's style.display is set to '' (it's visible)

7) Repeat

 

So far this works. Using DOM the user can select as many images as he wants, but when I try to use PHP to process the form, $_FILES['input_name']['name'] doesn't return a value.

 

Is the use of DOM to create file inputs on-the-fly the reason for this? And if so, does that mean that I can't do what I'm trying to do? Any suggestions?

 

Thanks in advance

Put your input name as:

<input type="file" name=\"input_file[]\" />

 

So in your php, you refer $_POST['input_file'] as an array.

foreach($_POST['input_file'] as $str){
    echo $str . "<br />";
}

 

I just post on my last thread same things....

 

Anyway hope this help you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.