Upload de imagem TinyMCE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string Upload(HttpPostedFileBase file) | |
{ | |
string path; | |
string saveloc = "~/Uploads/Imagens"; | |
string relativeloc = "/Uploads/Imagens/"; | |
string filename = file.FileName; | |
if (file != null && file.ContentLength > 0 && IsImage(file)) | |
{ | |
try | |
{ | |
path = Path.Combine(HttpContext.Server.MapPath(saveloc), Path.GetFileName(filename)); | |
file.SaveAs(path); | |
} | |
catch (Exception e) | |
{ | |
return "<script>alert('Failed: " + e + "');</script>"; | |
} | |
} | |
else | |
{ | |
return "<script>alert('Failed: Unkown Error. This form only accepts valid images.');</script>"; | |
} | |
return "<script>top.$('.mce-btn.mce-open').parent().find('.mce-textbox').val('" + relativeloc + filename + "').closest('.mce-window').find('.mce-primary').click();</script>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment