Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @{
- var imagePath = "";
- WebImage photo = null;
- var FileName = "";
- if (IsPost)
- {
- photo = WebImage.GetImageFromRequest();
- if (photo != null)
- {
- FileName = Path.GetFileName(photo.FileName);
- imagePath = @"image\" + FileName;
- photo.Save(@"~\" + imagePath);
- }
- }
- if (Request["photoChoice"] != null)
- {
- imagePath = @"image\" + Request["photoChoice"];
- }
- }
- <!DOCTYPE html>
- <html>
- <head>
- <title>Галерея изображений</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <meta name="description" content="The description of my page" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <link rel="stylesheet" type="text/css" href="mystyle.css">
- </head>
- <body>
- <img src="~/Images/logo.png"/>
- <h1>Галерея</h1>
- <form style="line-height: 2.5;" action="~/ShowAll">
- <button type="submit">Просмотр галереи</button>
- </form>
- <form method="post" action="">
- <div>
- Выбор файла:
- <select name="photoChoice">
- @{
- <option selected disabled> Выберите:</option>
- DirectoryInfo files = new DirectoryInfo(Server.MapPath(@"~\image"));
- int i= 1;
- foreach (var f in files.GetFiles())
- {
- <option value="@f.Name"> Photo @i.ToString() - @f.Name</option>
- i++;
- }
- }
- </select>
-
- <input type="submit" value="Выбрать" />
- </div>
- <div style="padding:10px;">
- @if (imagePath != "")
- {
- <img src="@imagePath" alt="Ошибка: здесь должно было быть изображение" width="300" />
- <br />
- <a href="@Html.AttributeEncode(imagePath)" target="_Self">
- Открыть оригинал
- </a>
- }
- </div>
- </form>
- <form action="" method="post" enctype="multipart/form-data">
- <fieldset>
- <legend> Загрузить изображение </legend>
- <label for="Image">Image</label>
- <input type="file" name="Image" accept="image/*" />
- <br />
- <p> <input type="submit" value="Загрузить" /></p>
- </fieldset>
- </form>
- <div id="footer">
- <center> © , 2016</center>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement