fileinfo

c# 解压 zip 文件

偶尔善良 提交于 2020-02-28 04:01:16
var fileName = GetPath(_tempFileName); try { File.Delete(fileName); File.Copy(_args[0], fileName); if (!File.Exists(fileName)) { MessageBox.Show("Upgrade Failed, File Not Exist(升级失败,文件不存在)."); return; } var startKey = "v2rayN/"; using (ZipArchive archive = ZipFile.OpenRead(fileName)) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.Length == 0) { continue; } var fullName = entry.FullName; if (fullName.StartsWith(startKey)) { fullName = fullName.Substring(startKey.Length, fullName.Length - startKey.Length); } string entryOuputPath = GetPath(fullName); FileInfo fileInfo = new

网页 大文件分片上传处理

江枫思渺然 提交于 2020-02-26 23:36:29
总结一下大文件分片上传和断点续传的问题。因为文件过大(比如1G以上),必须要考虑上传过程网络中断的情况。http的网络请求中本身就已经具备了分片上传功能,当传输的文件比较大时,http协议自动会将文件切片(分块),但这不是我们现在说的重点,我们要做的事是保证在网络中断后1G的文件已上传的那部分在下次网络连接时不必再重传。所以我们本地在上传的时候,要将大文件进行分片,比如分成1024*1024B,即将大文件分成1M的片进行上传,服务器在接收后,再将这些片合并成原始文件,这就是分片的基本原理。断点续传要求本地要记录每一片的上传的状态,我通过三个状态进行了标记(wait loading finish),当网络中断,再次连接后,从断点处进行上传。服务器通过文件名、总片数判断该文件是否已全部上传完成。 下面来说细节: 1、首先获取文件(音视频、图片) 分两种情况,一种是在相册库里直接获取,一种是调用相机。如果是通过UIImagePickerView来获取(细节不详述,网上一大堆),我们会发现当你选定一个视频的时候,会出现图1的压缩页面,最后我们的app获取的视频就是这个经过压缩后的视频(不是视频库里的原始视频,这里有个注意点,操作完该压缩视频后记得释放,系统不会帮你释放的,需要你手动来操作,下面会说到),然后通过UIImagePickerView的协议方法中的- ( void

在C#中复制目录的全部内容

徘徊边缘 提交于 2020-02-26 10:44:35
我想在C#中将目录的全部内容从一个位置复制到另一个位置。 似乎没有办法使用没有大量递归的 System.IO 类来完成此操作。 如果我们添加对 Microsoft.VisualBasic 的引用,我们可以使用VB中的方法: new Microsoft.VisualBasic.Devices.Computer(). FileSystem.CopyDirectory( sourceFolder, outputFolder ); 这似乎是一个相当丑陋的黑客。 有没有更好的办法? #1楼 这是我的代码希望这个帮助 private void KCOPY(string source, string destination) { if (IsFile(source)) { string target = Path.Combine(destination, Path.GetFileName(source)); File.Copy(source, target, true); } else { string fileName = Path.GetFileName(source); string target = System.IO.Path.Combine(destination, fileName); if (!System.IO.Directory.Exists(target)) {

SpringBoot文件分片上传,断点续传

六月ゝ 毕业季﹏ 提交于 2020-02-26 10:20:22
前段时间做视频上传业务,通过网页上传视频到服务器。 视频大小 小则几十M,大则 1G+,以一般的HTTP请求发送数据的方式的话,会遇到的问题:1,文件过大,超出服务端的请求大小限制;2,请求时间过长,请求超时;3,传输中断,必须重新上传导致前功尽弃; 解决方案: 1,修改服务端上传的限制配置;Nginx 以及 PHP 的上传文件限制 不宜过大,一般5M 左右为好; 2,大文件分片,一片一片的传到服务端,再由服务端合并。这么做的好处在于一旦上传失败只是损失一个分片而已,不用整个文件重传,而且每个分片的大小可以控制在4MB以内,服务端限制在4M即可。 前端 Web前端可使用HttpUploader6的大文件上传控件6;官网地址: http://t.cn/EyI6vHh <div class="section section6 section5"> <div class="part1"><a href="javascript:;" target="_blank" class="part1__btn">批量删除</a><span class="part1__txt"><em class="part1__num" id="upload_num">0</em>个视频,共 <em class="part1__num" id="upload_size">0M</em></span></div>

Detect excel .xlsx file mimetype via PHP

痴心易碎 提交于 2020-01-14 04:35:08
问题 I can't detect mimetype for xlsx Excel file via PHP because it's zip archive. File utilite file file.xlsx file.xlsx: Zip archive data, at least v2.0 to extract PECL fileinfo $finfo = finfo_open(FILEINFO_MIME_TYPE); finfo_file($finfo, "file.xlsx"); application/zip How to validate it? Unpack and view structure? But if it's arcbomb? 回答1: I know this works for zip files, but I'm not too sure about xlsx files. It's worth a try: To list the files in a zip archive: $zip = new ZipArchive; $res = $zip

Python program to traverse directories and read file information

拈花ヽ惹草 提交于 2020-01-12 13:48:31
问题 I'm just getting started with Python but already have found it much more productive than Bash shell scripting. I'm trying to write a Python script that will traverse every directory that branches from the directory I launch the script in, and for each file it encounters, load an instance of this class: class FileInfo: def __init__(self, filename, filepath): self.filename = filename self.filepath = filepath The filepath attribute would be the full absolute path from root (/). Here's the

Severe fileinfo issues

依然范特西╮ 提交于 2020-01-05 07:00:28
问题 I am on shared hosting, and have been battling with them to get fileinfo working, we have finally got it working, but again I have been hit with another barrier, I have essentially got this because I am creating a new file upload tool and we need to know what mimetypes are being uploaded, but fileinfo does not want to play ball. So, a .sql file will return text/plain, correct. However, every other file will simply return application/octet-stream, what I am wondering is why this is the case, I

How to use Directory.EnumerateFiles excluding hidden and system files

亡梦爱人 提交于 2020-01-03 09:10:10
问题 I'm enumerating all files in a directory so that I can process them later. I want to exclude hidden and system files. This is what I have so far: IEnumerable<IGrouping<string, string>> files; files = Directory.EnumerateFiles(sourcePath, "*", SearchOption.AllDirectories) .Where(f => (new FileInfo(f).Attributes & FileAttributes.Hidden & FileAttributes.System) == 0) .GroupBy(Path.GetDirectoryName); However if I look at the results I am still getting hidden and system files included: foreach (var

Determining Filetype with PHP. What is Magic Database?

徘徊边缘 提交于 2020-01-03 08:41:32
问题 I'm trying to determine if some files are actually images (using PHP). I've been advised to use finfo and i'm trying to understand how it works. What I don't get is - what is a magic numbers database and how does it work? I'm a bit puzzled - does each file have certain "magic number" that you compare against that database? Also - I have it on my debian squeeze - but will it also be available on WIN platform? or would one have to attach that database along with the app? <?php $finfo = new

Determining Filetype with PHP. What is Magic Database?

感情迁移 提交于 2020-01-03 08:41:21
问题 I'm trying to determine if some files are actually images (using PHP). I've been advised to use finfo and i'm trying to understand how it works. What I don't get is - what is a magic numbers database and how does it work? I'm a bit puzzled - does each file have certain "magic number" that you compare against that database? Also - I have it on my debian squeeze - but will it also be available on WIN platform? or would one have to attach that database along with the app? <?php $finfo = new