확인이 내보기
@using (Html.BeginForm("Upload", "Pictures", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div>
Title:<br/>
@Html.EditorFor(x => x.Title)<br/>
@Html.ValidationMessageFor(x => x.Title)<br/>
@Html.TextBoxFor(x => x.File, new {
type = "file"
})<br/>
@Html.ValidationMessageFor(x => x.File)<br/>
Description:<br/>
@Html.TextAreaFor(x => x.Description)<br/>
@Html.ValidationMessageFor(x => x.Description)
</div>
<div style="clear:both"></div>
<p><input type="submit" value="Save"/></p>
}
인이 내 시야 모델
public class UploadModel
{
[Required(ErrorMessage=("You have not selected a file"))]
public HttpPostedFileBase File { get; set; }
[Required(ErrorMessage = "Please enter a title")]
[StringLength(50)]
public string Title { get; set; }
[StringLength(400)]
public string Description { get; set; }
}
이 내 컨트롤러 조치입니다.
[Authorize(Roles = "Approved")]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Upload(UploadModel m)
{
byte[] uploadedFile = null;
Byte123 xxx = new Byte123();
if (m.File != null && !string.IsNullOrEmpty(m.Title))
{
//var fileName = System.IO.Path.GetFileName(m.File.FileName);
//string c = m.File.FileName.Substring(m.File.FileName.LastIndexOf("."));
// m.Title = m.Title.Replace(c, "");
uploadedFile = new byte[m.File.InputStream.Length]; //you get the image as byte here but you can also save it to file.
이것은 MVC 코드입니다. Web Forms를 사용하는 경우 코드가 더 짧아야합니다. 링크에서이 코드를 찾을 수 없으므로 코드를 게시했습니다. 또한 Cpanel을 사용하여 호스트에서 쓰기 권한이 활성화되어 있는지 확인해야합니다.
당신이 IIS에 그것을 실행하는 경우를 살펴 http://stackoverflow.com/questions/4877741/access-to-the-path-is-denied –
을 쓰기 활성화 : 여기
자세한 내용입니다 서버 Cpanel에 대한 사용 권한? 나는 Arvixe에서 나의 것을 주최하고 있으며 똑같은 문제가있다. 코드를 사용하여 FTP없이 업로드하는 경우 쓰기 권한을 활성화해야합니다. –