如何選取多個圖檔 上傳到FTP

只能上傳一個圖檔
<form  id="form1"   method = "POST"  enctype = "multipart/form-data" > 
    <input  type = "file"  name = "files[]"  multiple = "multiple"   /> 
    <input  type = "submit" /> 
 
</form >
<?

if(isset($_FILES['files'])){

	$ftp_server = "";
	$ftp_port = ;
	$ftp_user = "";
	$ftp_pass = "";
	$ftp_mode = FTP_BINARY;
	$conn = ftp_connect($ftp_server) or die("Could not connect");
	ftp_login($conn, $ftp_user, $ftp_pass)or die ("FTP 登入失敗");

		foreach ( $_FILES['files']['name'] as  $key => $name_value ){   //foreach陣列
			 $file_name[$key] =  $_FILES['files']['name'][$key];
			 $file_size[$key] = $_FILES['files']['size'][$key] ;
			 $file_tmp[$key] = $_FILES['files']['tmp_name'][$key];
			 $file_type[$key] = $_FILES['files']['type'][$key];
			
			 
				echo '檔案名稱'.$file_name[$key].'<br>';
				echo '暫存檔名'.$file_tmp[$key].'<br>';
				echo '檔案大小'.$file_size[$key].'<br>';
				echo '檔案類型'.$file_type[$key].'<br>';
		
		
				$img_m1 = substr($file_name[$key], 0, 1);
				$img_m2 = substr($file_name[$key], 1, 1);
				$file_path = $file_tmp[$key] ;
				$file_path1 = "/product/".$img_m1.'/'.$img_m2.'/'.$file_name[$key];

						 ftp_chdir ( $conn, $ftp_path) or die ("FTP 目錄切換失敗");

						 ftp_put ( $conn, "/product/".$img_m1.'/'.$img_m2.'/'.$file_name[$key] , $file_tmp[$key]  , FTP_BINARY) or die ("FTP 上傳失敗");
						 
						
						 echo '暫存路徑:'.$file_tmp[$key].'上傳路徑:'.$file_path1.'檔名:'.$file_name[$key];
							exit ("上傳成功");
				
			
			 
		}
		

				

	

		
ftp_close ( $conn);		
		
}

評論

Sign In or Register to comment.