if($photo!=""){
if($photo_size>5000){
error("文件太大","history.back(0)");
}
if (($photo_type== "image/pjpeg")OR($photo_type == "image/gif")){
$photodir="photo/".$loginname."/";
if($photo_type== "image/pjpeg"){
$type_pho=".jpg";
}elseif($photo_type == "image/gif"){
$type_pho=".gif";
}
if(!(file_exists($photodir)and is_dir($photodir))){
mkdir($photodir,0700);
}
$time=date("Y-m-d H:i:s");
$k=explode(" ",$time);
$k1=explode("-",$k[0]);
$k2=explode(":",$k[1]);
$photo_name=$k1[0]."_".$k1[1]."_".$k1[2]."_".$k2[0]."_".$k2[1]."_".$k2[2].$type_pho;
copy($photo,$photodir.$photo_name);
$query="insert into photo(username,photo,time) values('$loginname','$photo_name',now())";
$sql=$class->query($query);
if($sql){
error("照片上传成功","welcome.php?action=mydom");
}
}else{
error("传照片只能是JPG或GIF","history.back(0)");
exit;
}
}文件重复问题,你可以使用当前时候再去分解后再当文件名。如上:$k=explode(" ",$time);
$k1=explode("-",$k[0]);
$k2=explode(":",$k[1]);
$photo_name=$k1[0]."_".$k1[1]."_".$k1[2]."_".$k2[0]."_".$k2[1]."_".$k2[2].$type_pho;
//$loginname是用户登陆的用户名。把这个去掉也可以。
文件要新建一个目录专门来存放的。
本人这里只存文件的路径。没有存大小。你自已加一下吧。还有。这个代码是传图片的。
我想转文件的道理是一样。希望对你有帮忙。看一下吧。
不懂再说。
if($photo_size>5000){
error("文件太大","history.back(0)");
}
if (($photo_type== "image/pjpeg")OR($photo_type == "image/gif")){
$photodir="photo/".$loginname."/";
if($photo_type== "image/pjpeg"){
$type_pho=".jpg";
}elseif($photo_type == "image/gif"){
$type_pho=".gif";
}
if(!(file_exists($photodir)and is_dir($photodir))){
mkdir($photodir,0700);
}
$time=date("Y-m-d H:i:s");
$k=explode(" ",$time);
$k1=explode("-",$k[0]);
$k2=explode(":",$k[1]);
$photo_name=$k1[0]."_".$k1[1]."_".$k1[2]."_".$k2[0]."_".$k2[1]."_".$k2[2].$type_pho;
copy($photo,$photodir.$photo_name);
$query="insert into photo(username,photo,time) values('$loginname','$photo_name',now())";
$sql=$class->query($query);
if($sql){
error("照片上传成功","welcome.php?action=mydom");
}
}else{
error("传照片只能是JPG或GIF","history.back(0)");
exit;
}
}文件重复问题,你可以使用当前时候再去分解后再当文件名。如上:$k=explode(" ",$time);
$k1=explode("-",$k[0]);
$k2=explode(":",$k[1]);
$photo_name=$k1[0]."_".$k1[1]."_".$k1[2]."_".$k2[0]."_".$k2[1]."_".$k2[2].$type_pho;
//$loginname是用户登陆的用户名。把这个去掉也可以。
文件要新建一个目录专门来存放的。
本人这里只存文件的路径。没有存大小。你自已加一下吧。还有。这个代码是传图片的。
我想转文件的道理是一样。希望对你有帮忙。看一下吧。
不懂再说。
从数据库里调文件出来。可以使用
$photo_path="photo/".$r[username]."/".$r[photo];
//photo是从数据库里读出来的文件名
//username是区别是谁传的文件。也是从数据库里读出来的。如果上面没有加的话。这个就不要啦。如:$photo_path="photo/".$r[photo];
然后图片里<img name="" src="<?=$photo_path?>" width="80" height="100" alt="">