there's a similar question about this but honestly i still don't understand how it works.
here is the code:
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-preview thumbnail" style="width: 200px; height: 150px;">
</div>
<div>
<span class="btn btn-default btn-file"><span class="fileupload-new">Select image</span>
<span class="fileupload-exists">Change</span><input type="file" name="myimage" accept="image/*"></span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</div>
my questions is: 1.) how will i pass the image using $_POST[] or $_FILES[] ?
2.) does the <input type="file" name="myimage" accept="image/*">
handles both when the user clicks the "Select Image" and "Change"?
3.) or what way can i pass the image and upload it on the server using PHP?
use tag with enctype as multipart/form-data around this code to post your files.
First of all, you need to change version of the code above to latest one by changing: fileupload to fileinput. Else you will have trouble with displaying.
Here is simple example for you:
<form method='post' action='upload.php' enctype='multipart/form-data'>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 277px; height: 220px;">
<img src="../images/default_image.png" alt="...">
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 277px; max-height: 220px;"></div>
<div>
<span class="btn btn-default btn-file"><span class="fileinput-new">Select image</span><span class="fileinput-exists">Change</span><input type="file" name="file[]"></span>
<a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
</div>
</div>
<input type='submit' name='submit' value='SUBMIT' />
</form>
So when you submit the form, this will process upload.php. So to upload an image to server, you need to write code in this file to handle that. A simple code could be:
<?php
if(isset($_POST['submit'])){ // When you click submit the form
if(isset($_FILES['file']['tmp_name'])){ //check if there is a file has been submitted.
// count and loop through array of files(if multiple images are uploaded)
for($i=0; $i < count($_FILES['file']['tmp_name']);$i++)
{
// check if there is a file in the array
if(!is_uploaded_file($_FILES['file']['tmp_name'][$i]))
{
echo 'No file is uploaded';
}
else{
Code to handle image upload and store image path to array
}
All images path are in array, you need to serialize() it and save to database as normal
}
?>
Hope you might get the idea of how to use Jasny Fileinput to handle image upload.