I want to upload multiple images in MySql database in the same row - separated by a comma(,).
For uploading and processing the images I am using the DropZoneJS javascript library.
The PHP code of dropzone library for moving the images to the propertyimage folder:
Also, the below code is saved in a file let's say upload-dropzone-img.php and the code to upload the image on MySQL is written in other file called function.php
$folder_name = 'propertyimage/';
if(!empty($_FILES))
{
global $con;
$temp_file = $_FILES['file']['tmp_name'];
$location = $folder_name . $_FILES['file']['name'];
move_uploaded_file($temp_file, $location);
}
if(isset($_POST["name"]))
{
$filename = $folder_name.$_POST["name"];
unlink($filename);
}
$result = array();
$files = scandir('propertyimage');
$output = '<div class="row">';
if(false !== $files)
{
foreach($files as $file)
{
if('.' != $file && '..' != $file)
{
$output .= '
<div class="col-md-2">
<img src="'.$folder_name.$file.'" class="img-thumbnail" width="175" height="175" style="height:175px;" />
<button type="button" class="btn btn-link remove_image" id="'.$file.'">Remove</button>
</div>
';
}
}
}
$output .= '</div>';
I want to store the $location variable data into the MySql database with comma-separated.
My HTML code :
<form method='POST' action='' enctype='multipart/form-data'>
<input id='dZUpload' type='file' name='propimage[]' multiple='multiple'/>
<input type='submit' name='uploadimg value='Upload' />
</form>
My PHP code to upload image (only the image upload part):
$folder_name = 'propertyimage/';
$temp_file = $_FILES['propimage']['tmp_name'];
$location = "propertyimage/" . $_FILES['propimage']['name'];
move_uploaded_file($temp_file, $location);
Bascially what I am trying to do here is to store the path of the image not the image itself. But got error as
And same data stores into mysql database
How to replace this /Array with the image file name like propertyimage/someimagename.png