html5文件上传asp mvc vs php

时间:2011-12-02 01:44:35

标签: php asp.net-mvc html5 file-upload

我喜欢这个多文件上传:

http://www.sitepoint.com/html5-javascript-file-upload-progress-bar/

但是后端示例是在php中,有人可以帮助我将其转换为asp.net mvc3,或者一个不错的起点,不知道从哪里开始:

<?php
$fn = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
if ($fn) {

    // AJAX call
    file_put_contents('uploads/' . $fn,file_get_contents('php://input'));
    echo "$fn uploaded";
    exit();
}
else {
    // form submit
    $files = $_FILES['fileselect'];
    foreach ($files['error'] as $id => $err) {
        if ($err == UPLOAD_ERR_OK) {
            $fn = $files['name'][$id];
            move_uploaded_file($files['tmp_name'][$id],'uploads/' . $fn);
            echo "<p>File $fn uploaded.</p>";
        }
    }
}

1 个答案:

答案 0 :(得分:1)

只需创建一个以HttpPostedFileBase fileselect作为参数的操作。

MVC将完成其余的工作。