dougou5852 2012-07-24 17:03
浏览 54
已采纳

将ASP.NET代码转换为PHP [关闭]

I was reading this tutorial.

http://ben.onfabrik.com/posts/pagedown-markdown-editor-custom-image-dialog

At the end of it there is ASP.NET code

[HttpPost]
public ActionResult EditorUpload(MediaEditorUploadModel model)
{           
    string result;
    var serializer = new JavaScriptSerializer();

    if (model.File.IsValidFile() && model.File.IsImage()) {
        // upload the file

        result = serializer.Serialize(
            new { success = true, imagePath = "http://{the url of the uploaded image}"});
    } else {
        result = serializer.Serialize(
            new { success = false, message = "Invalid image file"});
    }

    return Content(result); // IMPORTANT to return as HTML
}

But I have no idea, How I must respond it in PHP. Can anyone help me to translate this code into PHP?

  • 写回答

1条回答 默认 最新

  • doulai8405 2012-07-24 17:54
    关注

    First off I'm not going to attempt to pretend that I know ASP.NET well. So with that, based on my glance over the code you provided. It actually looks like it could be type of language, doesn't appear to me at the least eccentric to any given scripting type. Looks like Object Oriented code to me. But thats a mute point.

    Overall what the code appears to be doing is, instantiating another class which I would assume is the bulk of the code you'd much rather look at. But from this little snip its using the class to validate if the file is found, and is indeed an image in this case. If it is, then give a URL base on its location on the server. If not give an error. It also appears that its outputting in JSON format so a JavaScript can pick it up and use it, in example an AJAX request.

    That said, there a means via PHP to verify if the file is on your server with http://php.net/manual/en/function.file-exists.php

    then depending on what version of PHP your running you could use http://php.net/manual/en/function.finfo-file.php (if newer php version) or http://php.net/manual/en/function.mime-content-type.php (older php version)

    to get the file type, where there you would do a similar if-else with php based on those, that you provided in the ASP snipplet. You would output a json_encoded array for valid or good.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
  • ¥15 51嵌入式入门按键小项目
  • ¥30 海外项目,如何降低Google Map接口费用?
  • ¥15 fluentmeshing
  • ¥15 手机/平板的浏览器里如何实现类似荧光笔的效果
  • ¥15 盘古气象大模型调用(python)
  • ¥15 传人记程序做的plc 485从机程序该如何写
  • ¥15 已知手指抓握过程中掌指关节、手指各关节和指尖每一帧的坐标,用贝塞尔曲线可以拟合手指抓握的运动轨迹吗?
  • ¥50 libwebsockets 如何添加其他socket事件回调
  • ¥50 实现画布拖拽算子排布,通过flink实现算子编排计算,请提供思路
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部