Upload Multiple file - php

Source Code :
<form role="form" action="uploadrit.php" method="post" enctype="multipart/form-data">
<label class="input" >Choose File Of CSV Format</label>
<input class="input" type="file" name="file" id="file" class="form-control" required="required">
<button class="input" type="submit" name="AddFile" class="btn btn-primary">Submit</button>
</form>
I want to select all file from directory using file upload control and send one by one file to uploadrit.php.

You should add multiple attribute to your file tag:
<form role="form" action="uploadrit.php" method="post" enctype="multipart/form-data">
<label class="input" >Choose File Of CSV Format</label>
<input class="input" type="file" name="file" multiple id="file" class="form-control" required="required">
<button class="input" type="submit" name="AddFile" class="btn btn-primary">Submit</button>
</form>
If you need to handle the files via Javascript, you can use File API. Example documentation: http://developer.mozilla.org/en-US/docs/Using_files_from_web_applications

Instead sending the files one by one, use the multiple flag and send the files as an array. Here is an example:
<form action="file-upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload">
</form>
Pay attention to input where I've used the multiple flag as well as have declared the name of the input as an array. In your PHP file, loop through $_FILES['files'] to get all selected files.

Related

Multiple Images from separate input fields with php ajax

How to insert and update multiple images from multiple input fields in one form with PHP Ajax.
For example:
<form>
<input type="file" name="img1">
<input type="file" name="img2">
<input type="file" name="img3">
<input type="submit" value="Save">
</form>
Put your input name into an array.
<form>
<input type="file" name="img[]">
<input type="file" name="img[]">
<input type="file" name="img[]">
<input type="submit" value="Save">
</form>

$_FILES uploads only 1 file

<label class="labelFile">Bestand kiezen...</label>
<input type="file" name="images_1" class="fileChoose" accept="image/*"></br></br></br>
<label class="labelFile">Bestand kiezen...</label>
<input type="file" name="images_2" class="fileChoose" accept="image/*"></br></br></br>
It only fills the first image and the second one it gives an errors: "4", how to fix it,
I want multiple input fields not 1 multiple :D
if you put the form with
<form method="POST" enctype="multipart/form-data" >
two items are returned to you
try like this
<?php
var_dump($_FILES['images_1']);
var_dump($_FILES['images_2']);
?>
<form method="POST" enctype="multipart/form-data" >
<label class="labelFile">Bestand kiezen...</label>
<input type="file" name="images_1" class="fileChoose" accept="image/*"></br></br></br>
<label class="labelFile">Bestand kiezen...</label>
<input type="file" name="images_2" class="fileChoose" accept="image/*"></br></br></br>
<button value="ppp" type="submit">send </button>
</form>

Submitting an image alongside a form with one button

I have a regular form which submits to my database but I want to include a file upload in the form, so as to receive the form input in the expected table using PHP post and also receive the uploaded image.
Use <input type="file"> to include a file upload in the form.
Use something like this to send Files as well as other inputs to the processing page where you can access files and post variables.
<form action="#" method="post" enctype="multipart/form-data">
<input type="text" name="txtbox">
<br />
<input type="file" name="filebox">
<br />
<input type="submit" name="submit" value="submit">
</form>
When this is submitted you can access the data from $_FILES and $_POST
There are various input types in HTML just as the below:
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">
Each of the above inputs demand different conditions and formats to be satisfied.
For your query the answer is either:
<input type="file">
For webpages that require inputs in a file format. Or,
<input type="image">
For webpages requiring input in an image format.
For further details view the below link for help:
https://www.w3schools.com/html/html_form_input_types.asp

using one input file with two different form

Is there a way to using a input file with two different form?
I need only one input file and have to post this file to .php page depending of user selection.
Thanks.
<label for="file">Photo:</label>
<input type="file" name="file" id="file">
<form action="c.php" method="post" enctype="multipart/form-data" >
<input type="submit" name="submit" value="C">
</form>
<form action="d.php" method="post" enctype="multipart/form-data">
<input type="submit" name="submit" value="D">
</form>
You could redirect to page cd.php which includes c.php or d.php depending on the value C or D

Smarty Uploading a File with normal Input Files

In my index.php file , I got a code is trace the $_FILE, but seems like when uploaded a pic/jpeg/images file, the return result is 'array(0) { }'. Did I need use smarty's method to assign a input file's method?
var_dump($_FILES);
my photoupload.tpl
<form action="index.php?view=photoupload" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file">
<input class="btn_name" type="submit" name="submit" value="Submit">
</form>
No, you dont have to, heres a part of my current project where i work with smarty:
<form action="upload_contract.php" enctype="multipart/form-data" method="post">
...
<div class="row">
<div class="large-5 columns">
<label for="upload">Dateiupload:</label><span><input type="file" id="upload" name="upload"></span>
</div>
</div>
This one works fine without additional methods.

Categories