1

我想上传一个图像文件,然后提取其基本信息(作者、尺寸、创建日期、修改日期等)并将其显示给用户。我该怎么做。

在 asp.net c# 代码中对此问题的解决方案或参考会有所帮助。但是 javascript 或 php 也可以。

4

4 回答 4

1

检查此链接。您将根据 Win-OS 版本获得更多关于 GetDetailsOf() 及其文件属性的许可。

如果您想使用 C# 代码,请使用以下代码获取元数据:

List<string> arrHeaders = new List<string>();

 Shell shell = new ShellClass();
 Folder rFolder = shell.NameSpace(_rootPath);
 FolderItem rFiles = rFolder.ParseName(filename);

 for (int i = 0; i < short.MaxValue; i++)
 {
      string value = rFolder.GetDetailsOf(rFiles, i).Trim();
      arrHeaders.Add(value);
 }
于 2013-05-23T11:34:17.303 回答
0
Bitmap image = new Bitmap(fileName);
PropertyItem[] propItems = image.PropertyItems;

foreach (PropertyItem item in propItems)
{
  Console.WriteLine("iD: 0x" + item.Id.ToString("x"));
}

MSDN 参考

C# 教程参考

于 2013-05-23T11:37:25.597 回答
0

C# 解决方案可以在这里找到: Link1 Link2

于 2013-05-23T11:38:31.800 回答
-1

尝试这个...

    private string doUpload()
    {
        // Initialize variables
        string sSavePath;

        sSavePath = "images/";

        // Check file size (mustn’t be 0)
        HttpPostedFile myFile = FileUpload1.PostedFile;
        int nFileLen = myFile.ContentLength;
        if (nFileLen == 0)
        {
            //**************
            //lblOutput.Text = "No file was uploaded.";
            return null;
        }

        // Check file extension (must be JPG)
        if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")
        {
            //**************
            //lblOutput.Text = "The file must have an extension of JPG";
            return null;
        }

        // Read file into a data stream
        byte[] myData = new Byte[nFileLen];
        myFile.InputStream.Read(myData, 0, nFileLen);

        // Make sure a duplicate file doesn’t exist.  If it does, keep on appending an 
        // incremental numeric until it is unique
        string sFilename = System.IO.Path.GetFileName(myFile.FileName);
        int file_append = 0;
        while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))
        {
            file_append++;
            sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)
                             + file_append.ToString() + ".jpg";
        }

        // Save the stream to disk
        System.IO.FileStream newFile
                = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename),
                                           System.IO.FileMode.Create);
        newFile.Write(myData, 0, myData.Length);
        newFile.Close();

        return sFilename;
    }
于 2013-05-23T11:49:50.237 回答