PHP上傳文件例子

if($_POST['Submit']!=""){//文件上傳     if ($_FILES['textfield']['tmp_name'] == ""){         echo"No File!!";         exit;     }      $title_name = $_COOKIE['cp_bianhao'];     $dir=ABS_ROOT."M_CPSJ/attachments/";     $dh = opendir($dir);     while (false !== ($filename = readdir($dh))) {         $files[] = $filename;     }     sort($files);     foreach($files as $value){         $value_arr=explode("|",$value);         if($title_name==$value_arr[0]){             unlink($dir.$value);         }      }     $file_name = ABS_ROOT."M_CPSJ/attachments/".$_COOKIE['cp_bianhao']."|".$_FILES['textfield']['name'];     $result=move_uploaded_file($_FILES['textfield']['tmp_name'] , $file_name);    // chmod($file_name,0777);*nux下才須要     if(!$result){         print_r($_FILES);     }     $sql="UPDATE `cpsj_cpda` SET `appendix_path` = '".ABS_ROOT."M_CPSJ/attachments/"."', `appendix_name` = '".$_COOKIE['cp_bianhao']."|".$_FILES['textfield']['name']."' WHERE `cp_bianhao` ='".$title_name."' ";     $result=$db_con->db_query($sql);     if ($_COOKIE['sn']!=""){         Header("Location:cpda_cx.php");          setcookie("cp_bianhao","",time()-60*60*24*365);         setcookie("number","",time()-60*60*24*365);         setcookie("sn","",time()-60*60*24*365);     } }
相關文章
相關標籤/搜索