我正在上传一个文件在php中,如果它是一个csv文件,只想上传它.我相信我的语法适合内容类型.当它是一个csv文件时,它总是转到else语句.我在这做错了什么?
if (($_FILES["file"]["type"] == "text/csv"))
{
}
else
{
}
Run Code Online (Sandbox Code Playgroud)
如果我更改内容类型,它适用于该格式而不是csv.
任何人都知道如何在Edge工作?
<input type="file" accept=".csv">
适用于Chrome 44,Firefox 39,IE 11,Opera 31.
也试过了
<input type="file" accept=".csv,text/csv">
根据Stack Overflow上的这个答案,我们可以设置a的accept属性<input type="file" />来过滤接受的输入,如下所示:
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
Run Code Online (Sandbox Code Playgroud)
但是,正如您可以注意到运行下面的简单代码段,Chrome 43.0.something似乎只是忽略了这种配置,而Firefox 39.0则完全理解了这一点.
我考虑使用以下方法切换到更直接的方法:
accept=".xls, .xlsx"
Run Code Online (Sandbox Code Playgroud)
...在Chrome中工作正常,但使Firefox有点混乱,只接受使用.xlsx扩展名的文件.
考虑到这可能是非常普遍和基本的,我必须遗漏一些东西:我在哪里搞砸了?如何获取html5文件输入以仅在浏览器中建议.xls和.xlsx文件一致?
这是一个代码片段,说明了我的问题(以及一个JSFiddle链接,以防你想要它).
Accepts application/vnd.ms-excel and the likes:<br />
<label for="file1">File input</label>
<input type="file" name="file1" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"/>
<hr />
Accepts .xls and .xlsx:<br />
<label for="file2">File input</label>
<input type="file" name="file2" accept=".xls, .xlsx"/>Run Code Online (Sandbox Code Playgroud)
我的HTML看起来像这样:
<form>
<input type="file" name="txtFile" pattern="?" id="txtFile" class="required"/>
</form>
pattern = '?'
Run Code Online (Sandbox Code Playgroud)
使用哪个正则表达式我将添加唯一CSV文件允许的验证.
如果我上传.xls或任何其他文件,那么它将显示错误.
我想让我的输入只接受来自图库的文件而不是允许用户打开相机.
我怎样才能实现它?
ASP.NET
<asp:FileUpload ID="filGallery" runat="server" AllowMultiple="true" />
Run Code Online (Sandbox Code Playgroud)
HTML 5
<input type="file" id="filGallery" multiple="multiple" />
Run Code Online (Sandbox Code Playgroud)
我想要的行为类似于iOS 8或更低版本中的行为,其中启用了多个文件的输入无法打开相机
我在 html 页面有这个
<input type="file" id="ajax-upload-id-1508413400253" name="Media" accept="video/*,image/*"
style="position: absolute; cursor: pointer; top: 0px; width: 100%; height:
100%; left: 0px; z-index: 100; opacity: 0;">
Run Code Online (Sandbox Code Playgroud)
在 .js 中
manageMedia_Uploader = $("#fileuploader").uploadFile({
url: "/Ajax/JsonProvider?Method=SaveMedia",
fileName: "Media",
autoSubmit: false,
multiple: false,
acceptFiles: "video/*,image/*",
dynamicFormData: function () {
return { MediaFriendlyName: $("#ManageMedia-MediaFriendlyName").val(), MediaID: mediaID }
},
SaveMedia: function (mediaID) {
if (mediaID == 0) {
manageMedia_Uploader.startUpload();
} else {
//util
}
},
Run Code Online (Sandbox Code Playgroud)
我的问题是我只想添加图片和视频而不添加其他内容。感谢这段代码在选择文件时给了我两个选项。自定义文件和所有文件。
acceptFiles: "video/*,image/*",
Run Code Online (Sandbox Code Playgroud)
如何阻止“所有文件”部分?只会出现自定义文件?
我使用 dropzone 作为 CSV/XLS 文件上传器。我使用此选项来过滤和限制 CSV/XLS 文件:
acceptedFiles: "text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
Run Code Online (Sandbox Code Playgroud)
现在我只能在 Windows 对话框中看到 XLS 文件,而看不到 CSV 文件。当然,当我将过滤器下拉菜单更改为所有文件时,我会看到 CSV 文件并选择它。但我想要解决这个问题的方法或选项。
您是否有同时查看 XLS/CSV 文件的解决方案?
我正在使用Plupload将.csv文件上传到我的网站.除了.csv在文件选择模型中没有正确过滤文件的问题外,它工作正常.
这是我用来过滤.csv文件的代码:
filters : [
{title : "Files of type", extensions : "csv"},
],
Run Code Online (Sandbox Code Playgroud) 我使用vaadin(7.1.9)的上传组件,现在我的问题是,我不能够限制什么样的可以与上传组件向服务器发送的文件,但我还没有发现任何用于此目的的API.唯一的方法是在上传后丢弃错误类型的文件.
public OutputStream receiveUpload(String filename, String mimeType) {
if(!checkIfAValidType(filename)){
upload.interruptUpload();
}
return out;
}
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?
我想将 .xlsx 文件上传到我的系统,条件是文件名包含指定的字符串。
例如:我想上传名称中包含“Paper”的文件,因此文件浏览器不应显示名称中不包含“Paper”的文件。
对于我在本文中附加的照片中的示例,不应显示文件“Order#...”。
我该怎么做?这个想法有可能实现吗?谢谢。
我使用html5输入标记来仅选择.csv文件.我到目前为止
<input type="file" id="files" name="files[]" accept=".csv" multiple />
Run Code Online (Sandbox Code Playgroud)
但是当我点击浏览时,它会显示所有文件类型.我怎样才能让它发挥作用?
谢谢.
我正在使用从网上找到的一篇文章中摘录的 JavaScript /AngularJS 代码。我对它做了一些调整,因为原来的帖子在 IE 11 上不起作用,但除此之外,我按照我发现的方式使用它。这段代码允许您将 Excel 文件上传并读取到 jQuery 数据表。
\n\n我缺少一项要求,如果可能的话,想寻求帮助。该要求是仅允许上传 Excel 文件,用户不应“看到”其他类型的文件。
\n\n这是我正在使用的代码:
\n\nAngularJS 控制器:
\n\nvar app = angular.module(\'MyApp\', []);\napp.controller(\'MyController\', [\'$scope\', \'$http\', function ($scope, $http) {\n\n $scope.SelectedFileForUpload = null;\n\n $scope.UploadFile = function (files) {\n $scope.$apply(function () { \n $scope.Message = "";\n $scope.SelectedFileForUpload = files[0];\n })\n }\n\n //Parse Excel Data \n $scope.ParseExcelDataAndSave = function () {\n\n var file = $scope.SelectedFileForUpload;\n\n if (file) {\n\n var reader = new FileReader();\n\n reader.onload = function (e) {\n\n var filename …Run Code Online (Sandbox Code Playgroud) html ×5
javascript ×4
html5 ×3
content-type ×2
csv ×2
file-upload ×2
input ×2
php ×2
angularjs ×1
asp.net ×1
dropzone.js ×1
excel ×1
java ×1
plupload ×1
syntax ×1
upload ×1
vaadin ×1
vaadin7 ×1
xls ×1