<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>信息发布</title>
<link rel="stylesheet" href="../css/css.css" type="text/css">

 
<?php 
	   include("../conn.php"); 
       // include("anti_sql2.php");
       $get_database_name=$_POST["database_name"];
	  

?>


<?php 

	        
           if(empty($_FILES['file']['name']))
	       {  
				 //$_FILES['file_name']['name']为获取客户端机器文件的原名称
		         $db_filename="";
				 echo "<script>alert('[软件提示]:请选择你要上图像文件.');</script>";
                 echo "<script>location.href='up1.php';</script>";
                 exit;
           }
		   
		   
		   if(!empty($_FILES['file']['name']))
		   {
		   
               
			    $oldfilename=$_FILES['file']['name'];
		   
		        //echo  "<br>";
		        //echo  "----上载信息如下------：";
		        //echo  "<br>";
                //echo "<br>A.原文件名为：".$oldfilename."<br>";    
	   
	            $start=strrpos($oldfilename,".");
                $filetype=substr($oldfilename,$start,strlen($oldfilename)-strrpos($oldfilename,"."));
                //echo "<br>B.原文件的类型为：".$filetype."<br>";
		        $filetype=strtoupper($filetype);
		   
		   
		        $ext_name=array(".JPG",".GIF",".PNG",".PCX",".JPEG",".BMP",".PSD",".TDA".".CDR");
                
				if(!in_array($filetype,$ext_name))
			    {
				 
				 echo "【软件提示】:文件类型是:".$filetype."<br>";
				 echo "<script>alert('[软件提示]：不能上传非图像格式的文件.');</script>";
                 echo "<script>location.href='admin_up_images1.php';</script>";
                 
                }
				
				
		  
                //echo "<br>C.上传文件的大小为（字节）：".$_FILES['file']['size'];
              
			   $max_size=30*1024*1024;   ///--------------------------20M
			 
			   if ($_FILES['file_name']['size']>$max_size) 
			   {
                 echo "<script>alert(' [软件提示]:文件超过30M，请改写后上传.');</script>";
                 echo "<script>location.href='admin_up_images1.php';</script>";
                 exit;
               }
		   
		       //取得保存文件的临时文件名（含路径）
		       //echo "<br>文件上传时的临时文件名为：".$_FILES['file']['tmp_name'];
					
			   //$new_filename=date("Y_m_d")."_".$oldfilename; 
			   srand((double)microtime()*1000000);
               $rand1=rand(1,9);
			   $rand2=rand(1,9);
               $rand=$rand1.$rand2;
			  
			
			   date_default_timezone_set('Etc/GMT-8');
               $rand_name=date("YmdHis");
			   $new_filename=$rand_name.$filetype;
			 		
           
		       //echo "<br>A.上传后文件名为：".$new_filename;  
			   //echo  "<br>"; 
			   //echo "<br>B.上传文件的大小为（字节）：".$_FILES['file']['size']."Bytes";
			   //echo  "<br>"; 
		
		       $new_filename=strtolower($new_filename);
			
		       $db_filename=strtolower($new_filename);   //utf-8 存入数据库，没有乱码
			
			   //---先转换为GB2312，上传成功！汉字没有乱码----------------------------
			   $new_filename=iconv("UTF-8","gb2312", $new_filename);  //
			   
			   
			   $new_db_name=iconv("UTF-8","gb2312", $get_database_name);  // 
               $savedir="../uploadpic/".$new_db_name."/".$new_filename;
			   $savedir2="../uploadpic/".$get_database_name."/".$new_filename;
	   
               if(move_uploaded_file($_FILES['file']['tmp_name'],$savedir))
	           {
                   $file_name=basename($savedir);       //取得保存文件的文件名（不含路径）
                   //echo "<br>文件上传成功！保存为：".$savedir;   //显示有乱码
				   echo "文件上传成功！文件名保存在：<font color=#0000ff>".$savedir2."</font>";
				   echo "<script language=javascript>";
                   echo "parent.document.getElementById('moviepic').value='$new_filename';";
                   echo "</script>";
				}
	           else
	           {
				  $dmsg="[提示]:错误操作!无法将文件上传，请检查站点根目录下是否存在"."/uploadpic/".$get_database_name."目录"; 
                  echo "<script language=javascript>";
                  echo "alert('$msg');";
                  echo "alert('[软件提示]:请刷新本页面');";
                  echo "</script>";
                  exit;
               }
		        
			
		
		
		   }
		
				 
	?>
	
	
   
   
   
   
   
   
   

</body>
</html>
