簡體   English   中英

Markitup圖片上傳php源代碼在asp.net中等效

[英]Markitup picture upload php source code equivalent in asp.net

我需要與此源代碼塊等效的asp.net。

/* The following is a very basic PHP script to handle the upload. One might also
* resize the image (send back the *new* size!) or save some image info to a
* database. Remember that you can modify the widget to include any data you'd like
* submitted along with the uploaded image.
*/ 

$upload_dir = '/var/www/vhosts/test/htdocs/uploads/';

$upload_path = $upload_dir . basename($_FILES['inline_upload_file']['name']);

$response = array();

if (move_uploaded_file($_FILES['inline_upload_file']['tmp_name'], $upload_path))
{

    $info = getImageSize($upload_path);

    $response['status'] = 'success';
    $response['width'] = $info[0];
    $response['height'] = $info[1];
    $response['src'] = 'http://'
. $_SERVER['HTTP_HOST']
. substr(realpath($upload_path), strlen(realpath($_SERVER['DOCUMENT_ROOT'])));

}
else
{
     $response['status'] = 'error';
     $response['msg'] = $_FILES['inline_upload_file']['error'];
}
echo json_encode($response);

無論如何,我只是用google搜索php函數並將其寫在asp.net中,並想在這里添加。 對於只想為markitup添加圖像上傳插件並將其應用於asp.net的人來說,這可能會有所幫助。

try
{
    string filePath = "/var/www/vhosts/test/htdocs/uploads/";

    if (Request.Files.Count <= 0)
    {
        Response.Write("Please select an image to upload");
    }
    else
    {
        for (int i = 0; i < Request.Files.Count; ++i)
        {
            HttpPostedFile file = Request.Files[i];
            file.SaveAs(Server.MapPath(filePath + file.FileName));

            Response.Write("{\"Uploaded FileName\":\"" + file.FileName + "\"}");

            // option to use System.IO fileinfo to get file information
            // FileInfo fileInfo = new FileInfo.... 
            // option to add an array to return file info + path etc.. 
        } 
    }
}
catch (Exception ex)
{
    Response.Write("{\"error\": \"" + ex.Message +"\"}");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM