0

我正在尝试在 asp.net mvc 视图中实现 uploadify 的检查脚本功能,但我无法确定我应该在控制器端使用什么键。下面是 php 脚本,但我对 php 不是很熟悉,无法确定 php 从 httprequest 中抓取了什么。有没有人实施过这个?文档有点稀疏(不存在)。

$fileArray = array();
foreach ($_POST as $key => $value) {
    if ($key != 'folder') {
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . $_POST['folder'] . '/' . $value)) {
            $fileArray[$key] = $value;
        }
    }
}
echo json_encode($fileArray);
?>
4

1 回答 1

0

这是任何人搜索的解决方案。基本上,uploadify 脚本会发送文件名和它在表单集合中生成的唯一键。您可以通过遍历 allkeys 来获得它。下面的控制器操作遍历表单 allkeys 集合,如果密钥不是文件夹(uploadify 文件夹参数也在表单集合中传递给 scriptCheck),它会检查文件是否已经存在。如果确实存在,则将键和值添加到字典中,然后将其返回给客户端。然后,uploadify 插件会提醒用户该文件存在,并让他们有机会取消上传。希望这可以帮助其他人。

public ActionResult FileExists(FormCollection forms)
    {
        Dictionary<string,string> fileArray = new Dictionary<string,string>();

        foreach (string key in forms.AllKeys)
        {
            if (key != "folder")
            {
                string targetDirectory = Path.Combine(Request.PhysicalApplicationPath, @"uploads\documents\");
                string targetFilePath = Path.Combine(targetDirectory, forms[key]);
                if (System.IO.File.Exists(targetFilePath)) fileArray.Add(key, forms[key]);
            }
        }

        return Json(fileArray);
    }
于 2009-11-18T04:23:18.637 回答