当前位置:编程学习 > php >>

php文件上传代码

php文件上传代码

<?php

 $uploadpath='../upload/';
 $uploadtype='image/x-pngimage/gifimage/pjpeg';
 $uploadsava='';
 $uploadpath.=md5(date('y:m:d h:i:s')); 
 $phototype=isset($_POST['select'])?$_POST['select']:"";
 $title=Strreplace(isset($_POST['title'])?$_POST['title']:"null");
 $say=Strreplace(isset($_POST['textarea'])?$_POST['textarea']:"null");
 $tdate=date("Y:m:d"); 
 $uploadtype=$_FILES['file']['type'];


 if ($phototype=='null' || $phototype==""){
 echo("<script>alert('图片上传失败,你还没有创建相册');history.back();</script>");
 exit();
 }
 if($title=="null" || $title=="" || strlen($title)>50){
 $title="暂无标题";
 }
 if($say=="null" || $say=="" || strlen($say)>500){
 $say="暂无说明";
 } 
 if(strpos('exit:image/x-png',$uploadtype)){
  $uploadsava=$uploadpath.".png";
 }
 if(strpos('exit:image/gif',$uploadtype)){
  $uploadsava=$uploadpath.".gif";
 }
 if(strpos('exit:image/pjpeg',$uploadtype)){
  $uploadsava=$uploadpath.".jpg";
 } 
 if($uploadsava==''){
 echo("<script>alert('只能上传.gif .jpg .png三类文件');history.back();</script>");
 exit();
 }
 if($_FILES['file']['size']>202400){
 echo("<script>alert('对不起,图片大小不能大于200K');history.back();</script>");
 exit();
 }
 

if(move_uploaded_file($_FILES['file']['tmp_name'],$uploadsava)){
 echo("<script>alert('图片上传成功');history.back();</script>");
 $sql="insert into photo(name,picpath,picdate,pichit,picsay,filesendid,phototype) values('$title','$uploadsava','$tdate',1,'$say','$xm','$phototype')";
 mysql_query($sql) or die('Insert Data Fail Errors'.mysql_error()); 
}else{
 echo("<script>alert('图片上传失败');history.back();</script>");
}   www.226511.com

?>

原创文章 载注明:  www.226511.com

补充:Php教程,Php常用代码
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,