如何将图像文件上传到数据库 [英] how to upload image file to the database

查看:76
本文介绍了如何将图像文件上传到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将图片网址上传到数据库并使用fileuploader将其复制到ur网站文件夹中的images文件夹?

how to upload an image url to a database and copy it to the images folder in ur website folder using fileuploader?

推荐答案

我希望它有所帮助你支持


以下数据库代码

i hope it''s help you

following code for database
string filePath = fileupload.PostedFile.FileName;
string CommFilename = System.IO.Path.GetFileName(filePath);

add this field [CommFilename] into database







以下代码用于保存文件夹中的文件




following code for saving file in folder

function upload()
{
            string filePath = fileupload.PostedFile.FileName;
            //only the attched file name not its path
            string fileName = System.IO.Path.GetFileName(filePath);
            string serverFolderPath = Server.MapPath("..");

           fileupload.PostedFile.SaveAs(serverFolderPath + "\\" + fileName);
}


if (FileUploadControl.HasFile)
            {
                try
                {
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    FileUploadControl.SaveAs(Server.MapPath("~/") + @"\Images\" + 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;
                }
            }





这将上传您选择的文件,我建议限制哪些类型的文件可以b虽然上传到你的图片文件夹。



This will upload a file of your choosing, I suggest limiting what types of files can b uploaded to your images folder though.


这篇关于如何将图像文件上传到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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