Created
January 10, 2021 10:03
-
-
Save neno-tech/1099b0d49337f9f829aba55d58796cbc to your computer and use it in GitHub Desktop.
web app สำหรับนักเรียนส่งงาน 10 ม.ค.63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> </h3> | |
<p> </p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ขอบคุณครับ