file-upload - 将 Textarea 内容上传为文件
问题描述
我想将textarea 的内容作为文件上传,因为内容超出了 php.ini 中的 max_input_vars 限制。将来可能会增加所以我更喜欢将其作为文件上传^^
我在文本区域中向用户显示内容,因此它是可编辑的:) 然后单击“保存”并将文本区域的内容作为文件发送。我能怎么做 ?
<span onclick="data_save();">Save</span>
<textarea id="textarea">
<?php
print_r($tab);
?>
</textarea>
<script type="text/javascript">
<?php
echo file_get_contents('/var/www/'.$jsdir.'/jquery-2.1.4.min.js');
?>
function data_save()
{
var textToWrite = document.getElementById("textarea").innerHTML;
var textFileAsBlob = new Blob([ textToWrite ], { type: 'text/plain' });
var fileNameToSaveAs = "ecc.plist";
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null)
{
// Chrome allows the link to be clicked without actually adding it to the DOM.
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
} else {
// Firefox requires the link to be added to the DOM before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
// downloadLink.click();
$.ajax({
url: 'data_save.php',
data: data,
type: 'POST',
success: function(retour)
{
if (retour.indexOf('Oups') != -1)
alert(retour);
},
error: function(obj, text, error)
{
alert("Oups.. " + obj.responseText);
}
});
}
</script>```
解决方案
不可能,用户必须自己下载和上传文件....
推荐阅读
- python - 根据变量值调用不同的函数
- sql - SQL查询仅获取值等于当前日期的列
- python - 如果字符串中包含停用词,则从字符串中删除一个元素
- google-app-maker - 如何防止appmaker中的重复记录?
- c# - 使用 UTF8 编码创建数据库
- amazon-web-services - 无法访问 tmp 目录中的文件
- python - MySQL 5.6 中的全局查询超时
- kotlin - Kotlin 与 Objective-C 框架的多平台/原生互操作性
- c# - 我如何从一开始就为场景中的每个按钮调用相同的函数?
- javascript - zk zAu.send 函数 - org.zkoss.zk.ui.event.MouseEvent 不能转换为 org.zkoss.zk.ui.event.ForwardEvent