HTML 5 Multi File Upload with PHP

HTML 5 multi file upload with PHP

Try

foreach ($_FILES['imageURL'] as $file) { 
echo $file['name'];
}

UPDATE:

Google found this tutorial which may help you

Upload Multiple Files HTML5 / PHP

I have a similar code actually in one of my projects. Try it.

foreach ($_FILES['files']['name'] as $f => $name) {
move_uploaded_file($_FILES["files"]["tmp_name"][$f], $file_path);
}

Look at the following page:
http://php.net/manual/en/function.move-uploaded-file.php

EDIT:
Nowhere in the code you provided, does it show that you actually give your file a filename, you simply refer to a path, rather than a path+filename+extension

move_uploaded_file($_FILES["files"]["tmp_name"][$f], $file_path . $name);

modifying my original code sample to be like the second one, should work.

Multiple File Upload with PHP

Replace input file name like files[] not like files see following form example:

<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="file" name="files[]" multiple="multiple" accept="image/*" />
<input type="submit" value="Upload!" />
</form>

Multiple File Upload with HTML 5 and PHP

In case someone will need this in future: I found the solution here:

// If we have files
if ( $_FILES )
{
// Get the upload attachment files
$files = $_FILES['upload_attachment'];

foreach ($files['name'] as $key => $value)
{
if ($files['name'][$key])
{
$file = array(
'name' => $files['name'][$key],
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);

$_FILES = array("upload_attachment" => $file);

foreach ($_FILES as $file => $array)
{
$newupload = insert_attachment($file,$post->ID);
}
}
}
}

How can I select and upload multiple files with HTML and PHP, using HTTP POST?

This is possible in HTML5. Example (PHP 5.4):

<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="my_file[]" multiple>
<input type="submit" value="Upload">
</form>
<?php
if (isset($_FILES['my_file'])) {
$myFile = $_FILES['my_file'];
$fileCount = count($myFile["name"]);

for ($i = 0; $i < $fileCount; $i++) {
?>
<p>File #<?= $i+1 ?>:</p>
<p>
Name: <?= $myFile["name"][$i] ?><br>
Temporary file: <?= $myFile["tmp_name"][$i] ?><br>
Type: <?= $myFile["type"][$i] ?><br>
Size: <?= $myFile["size"][$i] ?><br>
Error: <?= $myFile["error"][$i] ?><br>
</p>
<?php
}
}
?>
</body>
</html>

Here's what it looks like in Chrome after selecting 2 items in the file dialog:

chrome multiple file select

And here's what it looks like after clicking the "Upload" button.

submitting multiple files to PHP

This is just a sketch of a fully working answer. See PHP Manual: Handling file uploads for more information on proper, secure handling of file uploads in PHP.

Multiple file upload with php and html

The problem was a permission problem, the folder I was uploading to didn't have proper permissions. I used chmod -R 777 to change permission so that php can upload to that folder

Select multiple files individually and upload with PHP

I had same problem some time ago, but I could figure out workaround and here is what I do. Everytime when user click and select files I add css class to file input and make it hidden, and then I append new file input with same properties to the form. This works good and does not requires changes in backend, just slight changes on frontend. Hope this helps you.

How to loop through HTML5 multiple file upload?

$_FILES is multidimensional. With the syntax that you used, the Filenames would be accessible in

$_FILES['image_name']['name'][0] # for the first one
$_FILES['image_name']['name'][1] # for the second one

and so on.
Here is a link for reference Uploading Multiple Files



Related Topics



Leave a reply



Submit