Skip to content

Instantly share code, notes, and snippets.

@Renancp01
Created January 30, 2017 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Renancp01/efae5bdffd0328b12275b1ed21742750 to your computer and use it in GitHub Desktop.
Save Renancp01/efae5bdffd0328b12275b1ed21742750 to your computer and use it in GitHub Desktop.
Upload de imagem TinyMCE
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