dougou5852 2012-07-25 01: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-25 01: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.

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

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services