图片打包上传。 想做一个,自己打把文件打包上传到服务器,然后解压,出图片,添加进数据库,这个要怎么实现,高手拿点代码出来分享下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Server端就解压缩呗,然后Insert,或者直接文件系统保存不就得了 C# 解压using System;using System.Collections.Generic;using System.Text;using System.IO;using Microsoft.Win32;using System.Diagnostics;namespace Uni.UniCustoms{ public class clsWinrar { /// <summary> /// 是否安装了Winrar /// </summary> /// <returns></returns> static public bool Exists() { RegistryKey the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe"); return !string.IsNullOrEmpty(the_Reg.GetValue("").ToString()); } /// <summary> /// 打包成Rar /// </summary> /// <param name="patch"></param> /// <param name="rarPatch"></param> /// <param name="rarName"></param> public void CompressRAR(string patch, string rarPatch, string rarName) { string the_rar; RegistryKey the_Reg; object the_Obj; string the_Info; ProcessStartInfo the_StartInfo; Process the_Process; try { the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe"); the_Obj = the_Reg.GetValue(""); the_rar = the_Obj.ToString(); the_Reg.Close(); the_rar = the_rar.Substring(1, the_rar.Length - 7); Directory.CreateDirectory(patch); //命令参数 //the_Info = " a " + rarName + " " + @"C:Test?70821.txt"; //文件压缩 the_Info = " a " + rarName + " " + patch + " -r"; ; the_StartInfo = new ProcessStartInfo(); the_StartInfo.FileName = the_rar; the_StartInfo.Arguments = the_Info; the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //打包文件存放目录 the_StartInfo.WorkingDirectory = rarPatch; the_Process = new Process(); the_Process.StartInfo = the_StartInfo; the_Process.Start(); the_Process.WaitForExit(); the_Process.Close(); } catch (Exception ex) { throw ex; } } /// <summary> /// 解压 /// </summary> /// <param name="unRarPatch"></param> /// <param name="rarPatch"></param> /// <param name="rarName"></param> /// <returns></returns> public string unCompressRAR(string unRarPatch, string rarPatch, string rarName) { string the_rar; RegistryKey the_Reg; object the_Obj; string the_Info; try { the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe"); the_Obj = the_Reg.GetValue(""); the_rar = the_Obj.ToString(); the_Reg.Close(); //the_rar = the_rar.Substring(1, the_rar.Length - 7); if (Directory.Exists(unRarPatch) == false) { Directory.CreateDirectory(unRarPatch); } the_Info = "x " + rarName + " " + unRarPatch + " -y"; ProcessStartInfo the_StartInfo = new ProcessStartInfo(); the_StartInfo.FileName = the_rar; the_StartInfo.Arguments = the_Info; the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden; the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径 Process the_Process = new Process(); the_Process.StartInfo = the_StartInfo; the_Process.Start(); the_Process.WaitForExit(); the_Process.Close(); } catch (Exception ex) { throw ex; } return unRarPatch; } }} using ICSharpCode.SharpZipLib.Zip.Compression;using ICSharpCode.SharpZipLib.Zip.Compression.Streams;using ICSharpCode.SharpZipLib.GZip;string strPath = Server.MapPath("../Photo_tmp"); if(File1.PostedFile.FileName!="") { string mFileName=File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\")+1);//取得文件名 strPath+=mFileName; File1.PostedFile.SaveAs(strPath); string []FileProperties=new string[2]; FileProperties[0]=strPath; FileProperties[1]=strPhotoPath+@"\"; UnZip(FileProperties); if(File.Exists(strPath)) File.Delete(strPath); }public void UnZip(string[] args) { ZipInputStream s = new ZipInputStream(File.OpenRead(args[0])); ZipEntry theEntry = s.GetNextEntry(); while ((theEntry = s.GetNextEntry()) != null) { string directoryName = Path.GetDirectoryName(args[1]); string fileName = Path.GetFileName(theEntry.Name); Directory.CreateDirectory(directoryName); if (fileName != String.Empty) { FileStream streamWriter = File.Create(args[1]+theEntry.Name); int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } streamWriter.Close(); } } s.Close(); }或winrar 解压 System.Diagnostics.Process Process1 = new System.Diagnostics.Process(); Process1.StartInfo.FileName = "Winrar.exe"; Process1.StartInfo.CreateNoWindow = true; Process1.StartInfo.Arguments = " a -r " + strzipPath + " " + strPath; Process1.StartInfo.Arguments = " a -afzip " + strzipPath + " " + strPath; Process1.StartInfo.Arguments = " a -r "+strzipPath+" " + strPath; Process1.StartInfo.Arguments = " m " + strzipPath + " " + strPath; Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strPath 关于做手机网站的问题! 在将string转byte[]时报错:未找到任何可识别的数字 求助 发个自定义圆形Button(希望对新手有用) 如何实现两种颜色的平稳过渡? [求助]谁有关条码识别方面的c/s代码?麻烦相告! 自定义控件的属性与设计时支持问题........ !!有难度的SQL 语句 ,大家进来看看 分数用完了 有没有做WinForm开发的?产品部署麻烦吗? 求一個關於數據分組的算法 同正则表达式捕获组的不同个数 字符串为空问题
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Win32;
using System.Diagnostics;namespace Uni.UniCustoms
{
public class clsWinrar
{
/// <summary>
/// 是否安装了Winrar
/// </summary>
/// <returns></returns>
static public bool Exists()
{
RegistryKey the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
return !string.IsNullOrEmpty(the_Reg.GetValue("").ToString());
} /// <summary>
/// 打包成Rar
/// </summary>
/// <param name="patch"></param>
/// <param name="rarPatch"></param>
/// <param name="rarName"></param>
public void CompressRAR(string patch, string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
Directory.CreateDirectory(patch);
//命令参数
//the_Info = " a " + rarName + " " + @"C:Test?70821.txt"; //文件压缩
the_Info = " a " + rarName + " " + patch + " -r"; ;
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录
the_StartInfo.WorkingDirectory = rarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 解压
/// </summary>
/// <param name="unRarPatch"></param>
/// <param name="rarPatch"></param>
/// <param name="rarName"></param>
/// <returns></returns>
public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
try
{
the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
//the_rar = the_rar.Substring(1, the_rar.Length - 7); if (Directory.Exists(unRarPatch) == false)
{
Directory.CreateDirectory(unRarPatch);
}
the_Info = "x " + rarName + " " + unRarPatch + " -y"; ProcessStartInfo the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径 Process the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
return unRarPatch;
}
}
}
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.GZip;string strPath = Server.MapPath("../Photo_tmp");
if(File1.PostedFile.FileName!="")
{
string mFileName=File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\")+1);//取得文件名
strPath+=mFileName;
File1.PostedFile.SaveAs(strPath);
string []FileProperties=new string[2];
FileProperties[0]=strPath;
FileProperties[1]=strPhotoPath+@"\";
UnZip(FileProperties);
if(File.Exists(strPath))
File.Delete(strPath);
}
public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
ZipEntry theEntry = s.GetNextEntry();
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty)
{
FileStream streamWriter = File.Create(args[1]+theEntry.Name);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
s.Close();
}或winrar 解压
Process1.StartInfo.FileName = "Winrar.exe";
Process1.StartInfo.CreateNoWindow = true;
Process1.StartInfo.Arguments = " a -r " + strzipPath + " " + strPath;
Process1.StartInfo.Arguments = " a -afzip " + strzipPath + " " + strPath;
Process1.StartInfo.Arguments = " a -r "+strzipPath+" " + strPath;
Process1.StartInfo.Arguments = " m " + strzipPath + " " + strPath;
Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strPath