Skip to content

Instantly share code, notes, and snippets.

@neno-tech
Created January 10, 2021 10:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neno-tech/1099b0d49337f9f829aba55d58796cbc to your computer and use it in GitHub Desktop.
Save neno-tech/1099b0d49337f9f829aba55d58796cbc to your computer and use it in GitHub Desktop.
web app สำหรับนักเรียนส่งงาน 10 ม.ค.63
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html');
}
function uploadFiles(form) {
try {
var dropbox = "xxx";
var folder, folders = DriveApp.getFoldersByName(dropbox);
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(dropbox);
}
var blob = form.myFile;
var file = folder.createFile(blob);
file.setDescription("Uploaded by " + form.myName);
getFiles()
return "อัพโหลดไฟล์เรียบร้อยแล้ว";
} catch (error) {
return error.toString();
}
}
function getFiles() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var headers = [["Last Updated", "File Name", "File URL"]];
sheet.getRange("A1:C").clear();
sheet.getRange("A1:C1").setValues(headers);
var folder = DriveApp.getFolderById('xxx');
var files = folder.getFiles();
var i=1;
while(files.hasNext()) {
var file = files.next();
if(ss.getId() == file.getId()){
continue;
}
sheet.getRange(i+1, 1, 1, 3).setValues([[file.getLastUpdated(),file.getName(), file.getUrl()]]);
i++;
}
}
<!doctype html>
<style type="text/css">
body {
background-color: #FFFFFF;
}
</style>
<BR>
<BR>
<BR>
<div align="center">
<p><img src="xxx"></p>
<table width="459" border="0">
<tbody>
<tr>
<td width="462"><div align="center">
<hr>
</div>
<form id="myForm" align="center">
<input type="text" name="myName" placeholder="พิมพ์ชื่อ สกุล..">
<input type="file" name="myFile">
<input type="submit" value="Upload File"
onclick="this.value='Uploading..';
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;">
</form>
<div id="output"></div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
<style>
input { display:block; margin: 20px; }
</style>
<hr></td>
</tr>
</tbody>
</table>
<h3>&nbsp;</h3>
<p>&nbsp;</p>
</div>
@superguruman
Copy link

ขอบคุณครับ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment