multiple image uploading using php - php

i'm trying to upload multiple files at one time but not getting proper result. my code is as follow:
<?php
if (isset($_FILES['uploadfiles'])) {
print_r($_FILES);
}
?>
<form action="index.php" method="post" enctype="multipart/form-data">
<p>
<input type="file" name="uploadfiles" multiple="multiple" min="1" max="999"/>
<input type="submit" name="Upload"/>
</p>
</form>
when i use print_r($_FILES) it only dispays the first selected file details. kindly help me.

Try uploadfiles named as an array:
<input type="file" name="uploadfiles[]" multiple="multiple" min="1" max="999"/>

Related

php undefined index coming on uploading file with ['name']

<form action='' method='post'>
<input type="file" class="form-control" name="kk">
<input type="submit" class="form-control" name="submit">
</form>
<?php
if(isset($_POST['submit'])){
echo $_FILES["kk"]["name"];
}
?>
hi,i'm new to php,In this code undefined index kk coming on uploading file,i just want the file name...please help me out
add enctype="multipart/form-data" to form tag
You need to pass enctype="multipart/form-data" when you have to upload file
<form action='' method='post' enctype="multipart/form-data">
<input type="file" class="form-control" name="kk">
<input type="submit" class="form-control" name="submit">
</form>
<?php
if(isset($_POST['submit'])){
echo $_FILES["kk"]["name"];
}
?>

Echo $_FILES giving no results

I'm trying to make a simple file upload while learning how to do so.
code looks as following:
<form action="upload.php" method="post">
<input type="file" multiple="multiple" name="files[]"
enctype="multipart/form-data"><br><br>
<input type="submit" value="upload">
</form>
<?php
echo $_FILES["files"]['name']
?php
For some reason i get 0 results, I cant figure out why. I know that when I upload more files it'd be wise to run through them with a foreach loop, but for the sake of simplicity I'd rather have the results of 1 file first.
You need to correct your html like this
<form action="upload.php" enctype="multipart/form-data" method="post">
Then in upload.php:
print_r($_FILES);
Instead of echo try with
print_r($_FILES)
Also try to add to form tag code below
enctype="multipart/form-data"
I'm assuming both the HTML form and PHP upload code is written within this file upload.php. Please correct me if I'm wrong.
Change your form HTML to:
<form action="" enctype="multipart/form-data" method="post"> <!-- Form action can be omitted. enctype attribute is needed -->
<input type="file" multiple="multiple" name="files[]"/>
<br/><br/>
<input type="submit" value="upload" name ="submit" /> <!-- Add name here -->
</form>
Modify your PHP code:
<?php
if (isset($_POST['submit'])) {
echo "<pre>";
print_r($_FILES);
}
?>
Hope this helps.
Peace! xD
Correct html for you will be:
<form action="upload.php" enctype="multipart/form-data" method="post">
<input type="file" multiple="multiple" name="files[]"/>
<br/><br/>
<input type="submit" value="upload"/>
</form>
it must work
You may also try:
var_dump($_FILES);
print_r($_FILES);

Cannot display content of $_FILES

Have a look at the following code:
<?php
if (isset($_POST['email']))
{
$expertmail=trim($_POST['email']);
echo $expertmail;
$expertfile=$_FILES['upfile']['tmp_name'];
echo $expertfile;
}
?>
<form action="test.php" method="post" name="users" id="users" >
<input name="upfile" id="upfile" type="file" />
<input name="email" id="email" type="text" />
<input type="submit" name="submit_button" id="submit_button" value="ΑΠΟΣΤΟΛΗ" />
</form>
Why 'echo $expertfile' does not display anything?
Thank you
POST Method Uploads gives all the information you need to handle file uploads in PHP. For your case you need: enctype="multipart/form-data":
<form action="test.php" method="post" name="users" id="users" enctype="multipart/form-data">
As Salman A points out, you will also need to check to see if a file was uploaded.

var_dump only shows 1 array when upload more than 1 file

i have a script that uploads images and then crops them. but when i use
<input type="file" name="filename" multiple="multiple"/><br />
and then do a var_dump i only get 1 array instead of 'for example' 10 images.
My uploadform:
<form action="uploaded.php" method="POST" enctype="multipart/form-data">
<hr>
<input type="file" name="filename" multiple="multiple"/><br />
<br /><br />
<hr width="60" align="left">
<input type="submit" value="Upload" />
</form>
My code to see the uploades files:
<?php
session_start();
echo "<pre>";
var_dump($_FILES);
die();
?>
when i upload 10 images. it only shows the first selected and prints out 1 array.
Please help!
Thanks
EDIT: i think that i have to use a session for this. but how do i do that?
Same as any other form element used more then once: <input type="file" name="filename[]" multiple="multiple"/>

Tomcat 6 & PHP with enctype - No input data returned

I have this problem when I'm using PHP5/HTML on Apache-Tomcat6.
Here's an example for one of the forms I use in my site:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
Whenever I add the 'enctype' attribute to any form; neither the $_FILES['image'] is returned nor the $_POST variables. As long as the 'enctype' is not there, everything (except for the file input of course) works as expected. Can any one guide me please?
You won't be able to post data with a method of get on your form.
In test.html:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
In hello.php:
<?php
print_r($_POST);
print_r($_FILES);
Depending upon your server configuration, this will combine $_GET, $_POST, and $_COOKIE, but you'll still want to post with file inputs.
print_r($_REQUEST);

Categories