程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP基礎知識 >> PHP上傳文件例子實現代碼

PHP上傳文件例子實現代碼

編輯: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);
}
}

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved