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?
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.