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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.