[英]How to upload a plain/text file to google drive using Javascript?
[英]html: how to restrict upload file format to plain text
我需要在网页上具有上传文件功能。 我只希望人们能够选择.csv和纯文本(.txt)文件。
<input type="file" accept=".csv,text/plain" >
我知道接受属性可能有效。 但是有两个问题。
有人知道如何实现吗?
请注意,您在客户端执行的任何操作(例如使用input
标签中的accept
属性)都可以被客户端轻易地忽略/覆盖。 因此,如果您确实要阻止将指定类型以外的文件上传到服务器,则应在表单发布到的脚本中在服务器端进行某种检查。
如果您只想接受txt文件,请将您的接受从text / plain更改为accept=".csv,.txt"
$target="images/"; //path to upload
if( isset($_POST['submit']) ) //check if post is set
{
if $_FILES['file']['type'] != 'text/plain'
{
// error
} else {
//upload
move_uploaded_file($_FILES['file']['tmp_name'], $target);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.