Asp.net mvc 如何将图像上载到服务器并保存其路径
我想能够上传一个图像到服务器上,但不是将图像保存为数据库中的字节,我想保存路径,以便在查看页面中通过图像的路径调用图像。此外,上传图像时,如果未找到文件夹,则应上传到某个文件夹中创建一个。所有这些都应使用MVC5。任何帮助都非常有用欣赏我不太确定您想用什么语言来完成这项工作,但这是将照片保存到数据库中所需的实现方法。基本上你是怎么说的 照片被压缩了 照片被发送到服务器 服务器的api处理文件到文件夹中的存储 将folderpath+“文件名”保存到数据库中 下面是一个PHP方法上载,它是处理步骤3和4的服务器API的一部分 发现Asp.net mvc 如何将图像上载到服务器并保存其路径,asp.net-mvc,asp.net-mvc-5,Asp.net Mvc,Asp.net Mvc 5,我想能够上传一个图像到服务器上,但不是将图像保存为数据库中的字节,我想保存路径,以便在查看页面中通过图像的路径调用图像。此外,上传图像时,如果未找到文件夹,则应上传到某个文件夹中创建一个。所有这些都应使用MVC5。任何帮助都非常有用欣赏我不太确定您想用什么语言来完成这项工作,但这是将照片保存到数据库中所需的实现方法。基本上你是怎么说的 照片被压缩了 照片被发送到服务器 服务器的api处理文件到文件夹中的存储 将folderpath+“文件名”保存到数据库中 下面是一个PHP方法上载,它是处理步骤
什么编程语言?MVC 5是哪种语言/框架?你已经试过什么了?你面临的问题是什么?实际上我不知道如何编码,我正在寻找一些编码和评论方面的帮助这些链接将解决你的问题。
//upload API
function upload($id, $photoData, $title) {
// index.php passes as first parameter to this function $_SESSION['IdUser']
// $_SESSION['IdUser'] should contain the user id, if the user has already been authorized
// remember? you store the user id there in the login function
if (!$id) errorJson('Authorization required');
// check if there was no error during the file upload
if ($photoData['error']==0) {
// insert the details about the photo to the "photos" table
$result = query("INSERT INTO photos(IdUser,title) VALUES('%d','%s')", $id, $title);
if (!$result['error']) {
// fetch the active connection to the database (it's initialized automatically in lib.php)
global $link;
// get the last automatically generated ID in the photos table
$IdPhoto = mysqli_insert_id($link);
// move the temporarily stored file to a convenient location
// your photo is automatically saved by PHP in a temp folder
// you need to move it over yourself to your own "upload" folder
if (move_uploaded_file($photoData['tmp_name'], "upload/".$IdPhoto.".jpg")) {
// file moved, all good, generate thumbnail
thumb("upload/".$IdPhoto.".jpg", 180);
//just print out confirmation to the iPhone app
print json_encode(array('successful'=>1));
} else {
//print out an error message to the iPhone app
errorJson('Upload on server problem');
};
} else {
errorJson('Upload database problem.'.$result['error']);
}
} else {
errorJson('Upload malfunction');
}
}