如何在我的网站上的特定文件夹中上传图片 [英] how to upload an image in specific folder on my website

查看:55
本文介绍了如何在我的网站上的特定文件夹中上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.....
我要准备一个页面.在此用户中可以上传图片.

我使用了文件上传控件.这在本地系统上正常工作,但在我的网站上却不工作...

请为此发送特定的代码..
请帮助我...

hi.....
I want to prepare a page. In this user can upload an image.

I used file upload control. This is working properly on local system but it not working on my website...

please send a specific code for this..
plz help me...

推荐答案

您需要提供相对路径才能在服务器上运行它.


you need to give relative path to run this on server.


myFile.PostedFile.SaveAs(server.mappath("Images\myphoto.png");


protected void UploadButton_Click(object sender, EventArgs e)
     {
         if(FileUploadControl.HasFile)
           {
     try
     {
         string filename = Path.GetFileName(FileUploadControl.FileName);
         FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
         StatusLabel.Text = "Upload status: File uploaded!";
     }
     catch (Exception ex)
     {
         StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
     }
         }


     }


请检查下面提供的解决方案.确保您已经设置了必需的设置:

Please check the solution provided below. Make sure that you have already set the required settings:

protected void btnUploadPic_Click(object sender, EventArgs e)
{
    if(PicFileUploadCtrl.HasFile)
        {
        try
        {
            string strFileName = Path.GetFileName(PicFileUploadCtrl.FileName); // Get the name of the selected Pic
            PicFileUploadCtrl.SaveAs(Server.MapPath("~/") + strFileName );  // Save the selected Pic on the server
            lblStatus.Text = "Pic uploaded successfully!!!";
        }
        catch (Exception ex)
        {
            lblStatus.Text = "Error while uploading the Pic.";         

        }

}


这篇关于如何在我的网站上的特定文件夹中上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆