象动网论坛那样上传图片的方式,怎么实现,有人知道吗,最好有代码,它的在一个文本框里输入[IMG]图片路径[/IMG],然后提交就ok了,我是初学者,不明白它是怎么实现

解决方案 »

  1.   

    这样恐怕并没有将这个图片保存到服务器上,只是在显示的时候直接转换成
    <img src="图片路径">而已
      

  2.   

    不是吧,<img src="图片路径"> 图片路径是服务器的路径啊,服务器,没图片怎么可能呢
      

  3.   

    楼主说的是ubb代码吧,你所说的图片路径是不是指图片的url地址啊~~
    那样不是上传到服务器,而是在将其他地方的图片显示而已
      

  4.   

    这个是称为ubb代码..没有上传图片
      

  5.   

    //前台
    <TABLE cellSpacing="0" cellPadding="4" width="100%" border="0">
    <TR>
    <TD><FONT color="#ff0000">*</FONT>像片: <INPUT id="pic_url" type="file" maxLength="255" size="60" name="pic_url" runat="server">(小于500K字节)
    </TD>
    <td>
    <asp:Button id="btnsave" runat="server" Text="Button"></asp:Button>
    </td>
    </TR>
    </table>
    //后台
    private void btnsave_Click(object sender, System.EventArgs e)
    {
    fileName = this.pic_url.Value;
    if(fileName != null && fileName.Trim().Length > 0)
    {
    try
    {
    fileName=System.Guid.NewGuid().ToString()+fileName.Substring(fileName.LastIndexOf(@"."));
    pic_url.PostedFile.SaveAs(Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/UserImage/" + fileName));
    }
    catch
    {}
    }
    }
      

  6.   

    才要文件上传控件
    <INPUT id="File1" style="WIDTH: 264px; HEIGHT: 22px" type="file" size="24" name="File1"
    runat="server">
    <asp:label id="Span1" runat="server" Width="272px"></asp:label>
      

  7.   

    public void add_product(object sender,EventArgs e)
    {
    string filepath = Server.MapPath("images/"+Path.GetFileName (File1.PostedFile.FileName)); 
                shop.myData myData1=new shop.myData();
    if (File.Exists(filepath)) 

    Span1.Text="上传文件重名,请改名后再上传!";  
    return;  

    else 
    {
    int read=0;
    string SQL_pd="Select * from product where p_name='"+p_name.Value+"'";
       
    SqlDataReader reader_pd = myData1.executeQuery(SQL_pd);
    //如果已输入,则修改记录。否则就插入记录
    if(reader_pd.Read())//判断是否有该商品的记录
    {
    read=1;
    }
    else
    {
    read=0;
    }
    reader_pd.Close();
    myData1.closeConn();
    if(read==1)
    {
    Response.Write("<script language='JavaScript'>alert('"+"该商品已存在"+"'); </script>");
    }
    else if(read==0)//插入新记录
    {
                        string product_name=p_name.Value;
    int product_price=Convert.ToInt32(price.Value);
    string product_pic=Path.GetFileName(File1.PostedFile.FileName);
    int category_id=Convert.ToInt32(c_id.SelectedItem.Value);
    string product_memo=memo.Value;
    string insertcmd="insert into product(p_name,price,pic,c_id,memo) values('"+product_name+"','"+product_price+"','"+product_pic+"','"+category_id+"','"+product_memo+"')";

    try
    {//执行数据库插入操作
    myData1.executeUpdate(insertcmd);
    //将商品图片文件上传到服务器
    if(File1.PostedFile != null)
    {
    try
    {  
    File1.PostedFile.SaveAs(filepath);  
    }  
    catch (Exception exc)
    {  
    Span1.Text = "保存图片时出错<b>" + filepath + "</b><br>"+ exc.ToString();  
    }
    }
    Response.Write("<script language='JavaScript'>alert('"+"记录添加成功"+"'); </script>");
    Response.Write("<script>window.location='product_add.aspx';</script>");//刷新该页
    }
    catch (Exception ex)
    {
                           Response.Write(ex.ToString());
    Response.Write("<script language='JavaScript'>alert('"+"记录添加失败"+"'); </script>");
    }
    }
    }
      

  8.   

    /// </summary>
    /// <param name="strNodeId"></param>
    /// <param name="file"></param>
    /// <param name="description"></param>
    /// <param name="userId"></param>
    public void creatNewFile(string strNodeId,HtmlInputFile file,string description,string userId)
    {
    Stream imgdatastream = file.PostedFile.InputStream;
    string fileName = System.IO.Path.GetFileName(file.PostedFile.FileName).Trim();
    int imgdatalen = file.PostedFile.ContentLength;
    string imgtype = file.PostedFile.ContentType;
    byte[] imgdata = new byte[imgdatalen];
    int n = imgdatastream.Read(imgdata,0,imgdatalen);
    DataBase db = new  DataBase();
    DataSet ds ;
    db.Open();

    // check DB
    string  sqlcheck  = " SELECT * FROM T_DMS_DOC ";
    sqlcheck += " WHERE NodeId  = '"+ DataBase.SqlItemTextChange(strNodeId) +"'";
    sqlcheck += " AND   DocName = '"+ DataBase.SqlItemTextChange(fileName) +"'";
    sqlcheck += " AND   DelStatus = 0"; // not deleted

    db.ExecSQL(sqlcheck,"T_DMS_DOC",out ds); if(ds.Tables.Count!= 0 && ds.Tables[0].Rows.Count !=0)
    {
    throw new Exception("1011");
    }

    // Get Document ID
    double randomStr = new System.Random().NextDouble()* 1000000000;
    string docID = DateTime.Now.ToString("yyyyMMdd") + (Math.Floor(randomStr)).ToString(); // Insert File to DB
    string sql  = " INSERT INTO T_DMS_DOC (NodeId,DocId,Version,DocName,Content,Description,UpdDate,UpdUid,CheckOut,DelStatus) ";
    sql += " VALUES( '"+ DataBase.SqlItemTextChange(strNodeId) +"','"+docID+"',1,'"+DataBase.SqlItemTextChange(fileName) +"',@imgdata,'"+DataBase.SqlItemTextChange(description)+"',GETDATE(),'"+DataBase.SqlItemTextChange(userId)+"',"+"'0','0')" ; SqlCommand command = new SqlCommand(sql,db.Connection ); SqlParameter paramData = new SqlParameter( "@imgdata", SqlDbType.Image );
    paramData.Value = imgdata;
    command.Parameters.Add( paramData ); try
    {
    // db.BeginTrans();
    // Write Log
    LogManager.WriteLog("Execute  "+command.CommandText); int numRowsAffected = command.ExecuteNonQuery(); if(numRowsAffected !=1)
    {
    throw new Exception("1012");
    } LogManager.WriteLog("Success"); //db.CommitTrans();
    }
    catch(Exception ex)
    {
    LogManager.WriteLog("Failure  "+ ex.Message);
    db.RollBack();
    throw ex;
    }
    finally
    {
    db.Close();
    }
    }
    private void btnAdd_Click(object sender, System.EventArgs e)
    {
    try
    {
    // Input Check
    if( !StyleCheck.TextCheck(tbUploadFileDesc.Text.Trim()) )
    {
    throw new ApplicationException(this.GetMessage("1016"));
    } string nodeId = this.Request.QueryString["NodeID"].ToString();
    string descrip= tbUploadFileDesc.Text;
    string userId = UserInfo.EmpNum; if(tbUploadFileName.PostedFile.FileName.Trim().Length== 0 || tbUploadFileName.PostedFile.ContentLength ==0)
    {
    Response.Write("<script>alert('"+GetMessage("1008")+"')</script>");
    return;
    } DmsDB.DocOperateDB dms = new Dms.DmsDB.DocOperateDB(); dms.creatNewFile(nodeId,tbUploadFileName,descrip,userId); RegisterStartupScript("dd","<script>alert('"+GetMessage("1009")+"')</script>"); this.BackToMain( "0" );
    }

    catch(Exception ex)
    {
     this.lblError.Text = GetMessage(ex.Message);
    }
    }
    <TR>
    <TD align="right"><asp:Label id="lblUploadFileName" runat="server" Font-Size="Medium">File Name : </asp:Label></TD>
    <TD><INPUT id="tbUploadFileName"  style="WIDTH: 300px" type="file" runat="server"></TD></TR>
    <TR>