php+mysql图片的插入、显示操作代码

我使用dw编辑的php,连接了一个dorm的数据库,其中有一个member的table,M_No及M_Photo分别存放编号int型的,图片blob类型的
我想在php页面中插入电脑中的图片到数据库中(保存图片而不是图片路径),同时还可以从数据库中读取图片并显示在php页面中,代码该怎么写,请高手赐教(pS:如果要保存图片路径该怎么写,顺便解释一下)
谢了,最好写出关键代码,不要语言描述,我是刚学php的,可以给我邮件
[email protected]
如果要保存地址的话,当用户上传的时候应该也是保存到web服务器的地址里吧?而数据库中保存的应该是服务器上对应图片的地址,如果这样的话应该怎样实现呢,请贴出主要代码,谢谢.....(看了1楼的代码做了一下还是不太懂)PS:我是初学者,所以现在还停留在小白的境界,就麻烦大侠们帮忙细致的解释下,代码贴出,谢谢.....

如果存图片流,数据库会非常庞大,建议还是存路径,图片放到统一的目录下,方便管理
存就是insert 字段用vchar的存相对路径就可以了
读就是查数据库 然后放到数组里 、
显示<img src='读出来的变量'>就可以了

function uploadPhoto ($file) {

$this->result = false;
$this->error = false;
// -- save parameters
$this->_file = $file;
//get path
$this->createUploadDir();
$this->_destination=SystemProperties::$UPLOAD_ROOT_PATH['photo'];
//if (!is_null($allowed)) { $this->_allowed = $allowed; } else { $this->_allowed = array('jpg','jpeg','gif','png'); }

// -- check that FILE array is even set
if (isset($file) && is_array($file) && !$this->upload_error($file['error'])) {

// -- cool, now set some variables
$fileID=$this->_IDGenerator->getNextId('IMAGE');
$fileExt=$this->ext($file['name']);
$fileName =$fileID.'.'.$fileExt;
$this->createFileDir('image',$fileName);
$fileTmp = $file['tmp_name'];
//$fileSize = $file['size'];
//$fileType = $file['type'];
$fileError = $file['error'];

// -- update name
$this->_name = $this->_destination.$fileName;
// -- it's been uploaded with php
if (is_uploaded_file($fileTmp)) {
// -- where to put the file?
$filePath=$this->_fileUtil->getFilePath($fileName);
$output = $this->_destination.$filePath['filePath'];
//resize the img first
$isFileName_f=$this->resizeImage($this->_file,'f',$filePath['noExtFileName'].'_f'.$filePath['ext']);
//or resize the img like this,choosed type in ('a','b','c')
//$isFileName_b=$this->resizeImage($this->_file,'b',$filePath['noExtFileName'].'_b'.$filePath['ext']);
if($isFileName_a==true && $isFileName_b==true && $isFileName_c==true && $isFileName_d==true){
// -- just upload it
if (move_uploaded_file($fileTmp, $output)) {
chmod($output, 0644);
$this->result = basename($this->_name);
return $this->result;
} else {
$this->error("Could not move '$fileName' to '$this->_destination'");
}
}
} else {
$this->error("Possible file upload attack on '$fileName'");
}
} else {
$this->error("Possible file upload attack");
}
}

用php框架的,和纯php写不一样,但是问题不大就是一个思路,没有完全通用的代码,前台加个上传框,做个form传到后台就不用写了吧,传过来的参数$file就是文件,也是个数组用$_FILE[]能看到,首先校验后缀名或者前台js校验,move_uploaded_file这句是最重要的一句,其他都是辅助准备参数而已,意思就是把传上来的东西放到哪去,路径加文件名 $output 这个参数就是你要保存到数据库的值了
温馨提示:答案为网友推荐,仅供参考