I'm developing a website where multiple images are uploaded to a website and I'm playing around with ways that this can be done. At the moment I have a php script that will get & display images from a given folder which looks like this:
<?php
$dirname = "content/2014/February/";
$images = glob($dirname."*.*");
foreach($images as $image) {
echo '<img src="'.$image.'" /><br />';
}
?>
This works fine and I can format the <img>
using css and apply jquery for the gallery, BUT, how can I upload the folder of images using php and a html form in the first place?
Create The Upload File PHP Script$target_dir = "uploads/" - specifies the directory where the file is going to be placed. $target_file specifies the path of the file to be uploaded. $uploadOk=1 is not used yet (will be used later) $imageFileType holds the file extension of the file (in lower case)
A PHP script can be used with a HTML form to allow users to upload files to the server. Initially files are uploaded into a temporary directory and then relocated to a target destination by a PHP script. The user opens the page containing a HTML form featuring a text files, a browse button and a submit button.
HTML can be used to open a folder from our local storage. In order to open a folder from our local storage, use 'HREF' attribute of HTML. In the HREF attribute, we specify the path of our folder.
How to upload files/folders to my website? Navigate to the folder in which you want to upload from the folder/file tree on the left. Click the File Upload or the Folder Upload icon in the upper toolbar and choose the upload item from your computer. There is no file size limit for uploads in the File Manager.
It is possible to upload a folder now. You can get it done by following below code:
<input type="file" webkitdirectory mozdirectory />
You can check the demo here: https://jsfiddle.net/kevalpadia/vk6Ldzae/
I hope it will help you solve your issue.
The Current Answer is NOT supported by all browsers.
You can not upload a whole folder.
currently only chrome supports it
And to upload many files http://www.uploadify.com/
You can use HTML5's
<input type="file" multiple>
About processing uploads in PHP, read more here: http://php.net/manual/en/features.file-upload.post-method.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With