PHPファイルアップロード-マルチファイルアップロードの考え方

4233 ワード

2.          
①    name 
	<input type="file" name="file1">
	<input type="file" name="file2">
	<input type="file" name="file3">
	<input type="file" name="file4">
	
	a.              
	Array
		(
			[file1] => Array
				(
					[name] => 8.png
					[type] => image/png
					[tmp_name] => G:\wamp\tmp\php737.tmp
					[error] => 0
					[size] => 200
				)

			[file2] => Array
				(
					[name] => 28.png
					[type] => image/png
					[tmp_name] => G:\wamp\tmp\php738.tmp
					[error] => 0
					[size] => 6244
				)

			[file3] => Array
				(
					[name] => 54a296f8n6787b34c.png
					[type] => image/png
					[tmp_name] => G:\wamp\tmp\php739.tmp
					[error] => 0
					[size] => 3143
				)

			[file4] => Array
				(
					[name] => 54c0573dncb4db6f7.jpg
					[type] => image/jpeg
					[tmp_name] => G:\wamp\tmp\php788.tmp
					[error] => 0
					[size] => 5404
				)

		)

		          ,             
		    foreach    ,                  
		
	b.        
		①         
		$file = $_FILES;
			
		②      
			include('./functions.php');
		
		③        
			$path = './uploads/';	//          
			
		④        
			foreach($file as $v){
				$info = uploadFile($v,$path);
				
				⑤      
				if($info['isok']){
					echo '    '.$info['message'];
				} else {
					echo '    '.$info['message'];
				}
			}
---------------------------------------------------------------

②    name 
	a.     
		<input type='file' name="file[]">
		<input type='file' name="file[]">
		<input type='file' name="file[]">
		
	b.     
		<input type="file" name="file[]" multiple>
		
	
	c.      ,        
		Array
			(
				[userpic] => Array
					(
						[name] => Array
							(
								[0] => 8.png
								[1] => 9b2d7581fba543ec9bcf95e91018915a.gif
								[2] => 12.jpg
							)

						[type] => Array
							(
								[0] => image/png
								[1] => image/gif
								[2] => image/jpeg
							)

						[tmp_name] => Array
							(
								[0] => G:\wamp\tmp\php85E5.tmp
								[1] => G:\wamp\tmp\php85E6.tmp
								[2] => G:\wamp\tmp\php8635.tmp
							)

						[error] => Array
							(
								[0] => 0
								[1] => 0
								[2] => 0
							)

						[size] => Array
							(
								[0] => 200
								[1] => 16503
								[2] => 19443
							)

					)

			)
			
		          ,                   。
		                      ,      
			Array(
					[name] => 54c0573dncb4db6f7.jpg
					[type] => image/jpeg
					[tmp_name] => G:\wamp\tmp\php788.tmp
					[error] => 0
					[size] => 5404
				)
				
		        ,   $_FILES['file']                
		
	d.        
		①         
		$file = $_FILES['file'];
			
		②      
			include('./functions.php');
		
		③        
			$path = './uploads/';	//          
			
		④        
			foreach($file['name'] as $key=>$value){
				$data['name'] = $file['name'][$key];
				$data['type'] = $file['type'][$key];
				$data['tmp_name'] = $file['tmp_name'][$key];
				$data['error'] = $file['error'][$key];
				$data['size'] = $file['size'][$key];
			
				$info = uploadFile($data,$path);
				
				⑤      
				if($info['isok']){
					echo '    '.$info['message'];
				} else {
					echo '    '.$info['message'];
				}
			}
			
			a.  $file['name']       $key
			b.     ,            ,             
				     $key = 0;
					$data['name'] = $file['name'][0];	//               
					$data['type'] = $file['type'][0];	//               
					...
					
					         
						$data = array(
							[name] => 54c0573dncb4db6f7.jpg
							[type] => image/jpeg
							[tmp_name] => G:\wamp\tmp\php788.tmp
							[error] => 0
							[size] => 5404
						);
					                
					        ,        
					
					      $key=1,