I've implemented Filepicker.io in my HTML page for selecting and uploading one or more images.
The Filepicker.io functionality for selecting one or multiple files is working fine for me. User is able to select one or more images. Also if user wants to remove any of the selected images, he/she can remove them. Till here everything works fine for me.
Following is my working code for selecting one or multiple images using Filepicker.io:
<!DOCTYPE html>
<html>
<head>
<link href="vshare.css" type="text/css" rel="stylesheet"/>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.2.min.js">
</script>
<script src="http://api.filepicker.io/v1/filepicker.js"></script>
<script>
function filePicker(event) {
html = '';
for(var i=0;i<event.fpfiles.length;i++) {
mimetype = event.fpfiles[i].mimetype;
file = event.fpfiles[i].filename;
var extension = file.substr( (file.lastIndexOf('.') +1) );
switch(extension) {
case 'jpg':
case 'png':
case 'gif':
case 'jpeg':
html += '<div class="vshare_item">';
html += '<a class="vshare_item_delete" onclick="vshare_item_delete(this);"><i class="fa fa-times"></i></a>';
html += '<img src="'+event.fpfiles[i].url+'" class="vshare_item_img"/>';
html += '<input type="hidden" name="val[vshare]['+event.fpfiles[i].filename+'][]" value="'+event.fpfiles[i].url+'" />';
html += '</div>';
html += '<div class="clear"></div>';
break;
/*case 'doc':
case 'docx':
case 'ppt':
case 'pptx':
case 'pps':
case 'xls':
case 'xlsx':
case 'pdf':
case 'ps':
case 'odt':
case 'sxw':
case 'sxi':
case 'txt':
case 'rtf':
html += '<div class="vshare_item">';
html += '<a class="vshare_item_delete" onclick="vshare_item_delete(this);"><i class="fa fa-times"></i></a>';
html += '<img src="'+$("#global_attachment_vshare #sDocPath").val()+extension+'.png'+'" class="vshare_item_img"/>';
html += '<input type="text" name="val[vshare]['+event.fpfiles[i].filename+'][]" value="'+event.fpfiles[i].url+'" />';
html += '</div>';
html += '<div class="clear"></div>';
break;*/
default:
break;
}
}
$("#global_attachment_vshare #vshare_response").html(html) ;
$bButtonSubmitActive = true;
$('.activity_feed_form_button .button').removeClass('button_not_active');
}
function vshare_item_delete(args) {
$(args).parent(".vshare_item").remove();
}
</script>
</head>
<body>
<form action="sample_test.php" method="post">
<input type="filepicker" data-fp-apikey="Ajid7OnMRU2NCcKBMGTdNz" data-fp-mimetypes="*/*" data-fp-container="modal" data-fp-multiple="true" data-fp-services="BOX,DROPBOX,GOOGLE_DRIVE,EVERNOTE" onchange="filePicker(event);">
<input type="submit" name="Submit" value="Submit File">
</form>
</body>
</html>
If you simply create a blank HTML file on your machine and copy-paste the above code it will work for sure.
Now the issue I'm facing is I'm not able to create the hidden input fields on a form. These input hidden fields are for storing the file name and file path of selected file/files.
In my code I tried to store only the file name into hidden field but I also need to store file path as well. I'm not understanding where I'm doing something wrong so the hidden fields are not getting generated.
Can someone please help me in this regard? It would be of great great help to me.
If you have any other doubt, query regarding the issue I'm facing please do let me know. I'll be more than happy to help you.
Thanks for spending some of your valuable time in understanding my issue and showing interest in my issue.
Any kind of help, suggestion, comment, answer would be highly appreciated.
Waiting for your precious replies.