Is it possible with codeigniter, or even at all, to have only one input field that allows a user to select multiple files to upload. So basically you have
<input name="files" type="file">
rather than
<input name="file1" type="file">
<input name="file2" type="file">
<input name="file3" type="file">
I currently know how to implement the latter but think the former would be a cleaner model.
Have you even looked into PHP manual?
<form action="file-upload.php" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="userfile[]" type="file" multiple=""/><br />
<input type="submit" value="Send files" />
</form>
you access it in PHP as $_FILES
Your input has to be like this (so, you can select multiple files at once)
<input multiple type="file" name="files[]" />
Notice multiple attribute but not supported by all/old browsers.
An Example here and also take look at this tutorial.
Related
i am looking for a code that how to upload multiple text files to be input in different input fields like
<input type="file" name="file">
<input type="file" name="file2">
these files should be text files,upload to the specified directory and save this path to MySQL database later get the file paths for specified user only
You can make it in array as below.
<input type="file" name="file[]">
<input type="file" name="file[]">
Make sure to use enctype="multipart/form-data" in form tag.
<form action="http://localhost:8000" method="post" enctype="multipart/form-data">
<input type="file" name="file[]">
<input type="file" name="file[]">
</form>
And if you want to select multiple files with single file input then add multiple="multiple"
<input name="file[]" type="file" multiple="multiple" />
Actually I having one form will four File Input text box (Like Below).
While Submitting form means it is not sending data to server. When i seeing in console that status still in pending(See Below).
Don't why it is happening. Please Kindly help me to over come from this.
This Is my Code:
<form action="file.php" enctype="multipart/form-data" method="post">
Upload 1 <input type="file" name="file1"><br>
Upload 2 <input type="file" name="file2"> <br>
Upload 3 <input type="file" name="file3"> <br>
Upload 4 <input type="file" name="file4"> <br>
<input type="submit" value="Submit">
</form>
Thanks,
When I echo $_FILES['file']['name'] it gives it returns nothing
When I echo $_FILES['file']['name'][0] it returns the correct data.
How come that in every example they can use $_FILES['file']['name'] directly without the extra index?
How the $_FILES array is constructed is based on how your html input tags are named.
Your html input is likely
<input type="file" name="file[]" />
while in most examples it is
<input type="file" name="file" />
The first solution allows to duplicate this line exactly to receive multiple files simultaneously (in an array):
<input type="file" name="file[]" />
<input type="file" name="file[]" />
The second solution only allows exactly this single one file. If one needs to support multiple fileuploads, one has to create a html tag with a different value for the name attribute:
<input type="file" name="file1" />
<input type="file" name="file2" />
See this user comment in the php manual for a detailed example and the other comments around for futher information how to reorder this array (if one wishes to do so for whatever reason...)
I have a very basic PHP multiple file upload form:
<form action="file.upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $_REQUEST['id']; ?>" />
<input type="hidden" name="bypass" value="1" />
<input multiple type="file" name="file[]" id="file">
<input type="submit" name="submit" value="Submit">
</form>
Everything works fine for a few files, but when I upload too many large files, the hidden variables are no longer posted to PHP (!)
I am not sure what is causing the from variables to be ignored by PHP (?)
(I've checked with fiddler and the form indeed sends the right data from clientside... i.e., form fields bypass and id are both properly populated on clientside...)
I have a form such that a list of questions with inputs is followed by an invitation to upload files if they have them.
I have avoided nesting forms by popping up the form containing the upload. The difficulty is that if they press submit on the Uploader form, it will process the upload on the destination page, and likewise if they hit submit on the rest of the form, the uploads are not submitted.
How can I do both at once?
My code:
<form id="questions" action="page2.php" method="POST">
Question 1 <input name="q1"/>
Question 2 <input name="q2" />
Have any files to add? <button id="upload-button">Upload</button>
<input type="submit" value="Submit Answers" />
</form>
<div class="hidden">
<form id="fileupload" enctype="multipart/form-data" action="uploader.php" method="POST">
<input id="fileupload" type="file" name="files[]" multiple>
<input type="submit" value="Upload Files" />
</form>
</div>
jQuery will pop up the hidden div if someone presses the button to add files.
I don't have a problem with them being posted to the same place, but I tried using javascript to use the click event for each button to submit both forms and it did not work.
(Reading stack overflow later explained that only the last submission gets processed in this way)
Any ideas? Thanks
Very simply, structure your HTML like this, and process the logic from both page2.php and uploader.php in one shot (i.e. include the file-upload logic in page2.php). If you show us the contents of both of those files, I can show you how to combine them.
Also added labels with links to the associated inputs, and swapped the submit input for a button element.
<form id="questions" enctype="multipart/form-data" action="page2.php" method="POST">
<label for="q1">Question 1</label>
<input id="q1" name="q1" type="text" />
<label for="q2">Question 2</label>
<input id="q2" name="q2" type="text" />
<label for="fileupload">Upload a File<label>
<input id="fileupload" type="file" name="files[]" multiple />
<button type="submit">Submit</button>
</div>