Markitup图片上传php源码相当于asp.net

发布于 2025-01-07 09:02:54 字数 1009 浏览 0 评论 0原文

我需要此源代码块的 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);

I need asp.net equivalent of this source code block.

/* 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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北恋 2025-01-14 09:02:54

无论如何,我只是在 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 +"\"}");
}

Anyway i just googled about php functions and wrote it in asp.net and wanted to add here. It could be helpful for anyone who just want to add image upload plugin for markitup and apply it in 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 +"\"}");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文