2014-01-14 5 views
1

여러 이미지를 업로드 할 수있는 웹 사이트가 있는데 문제는 20 개가 넘는 이미지를 업로드하려고 할 때입니다. PHP는이 옵션이 20 개의 파일로 제한되어 있으므로 이미지를 업로드하기 전에 이미지를 업로드 할 수 있는지 알아보고 이미지를 하나씩 업로드하기 시작했는지 알고 싶습니다.제출하기 전에 여러 이미지 업로드

EDIT : bluimp 플러그인을 확인했는데 기본 코드와 비슷하지만 비슷한 작업을 수행하고 싶습니다. 문제는 그 시작점을

EDIT2을 알 수 없다는 것입니다 : 나는 해결책을 발견, 지금은 조사 놈이야에 대한 FormData

답변

0
당신은 쉽게 여기, 한 번에 여러 개의 파일을 업로드 작업 예입니다 수

내가

<?php 
if(isset($_FILES['files'])){ 
    $errors= array(); 
    foreach($_FILES['files']['tmp_name'] as $key => $tmp_name){ 
    $file_name = $_FILES['files']['name'][$key]; 
    $file_size =$_FILES['files']['size'][$key]; 
    $file_tmp =$_FILES['files']['tmp_name'][$key]; 
    $file_type=$_FILES['files']['type'][$key]; 
     if($file_size > 2097152){ 
     $errors[]='File size must be less than 2 MB'; 
     }  
     //$query="INSERT into upload_data (`USER_ID`,`FILE_NAME`,`FILE_SIZE`,`FILE_TYPE`) VALUES('$user_id','$file_name','$file_size','$file_type'); "; 
     $desired_dir="images/gallery"; 
    if(empty($errors)==true){ 
     if(is_dir($desired_dir)==false){ 
      mkdir("$desired_dir", 0700);  // Create directory if it does not  exist 
     } 
     if(is_dir("$desired_dir/".$file_name)==false){ 
      move_uploaded_file($file_tmp,"$desired_dir/".$file_name); 
     }else{         //  rename the file if another one exist 
      $new_dir="$desired_dir/".$file_name.time(); 
      rename($file_tmp,$new_dir) ;    
     } 
    // mysql_query($query);   
    }//else{ 
     // print_r($errors); 
    //} 
} 
//if(empty($error)){ 
    //echo "Success"; 
//} 
} 
?> 
<?php 
$b=$_FILES['files']['name']; 

$cc=implode (",",$b); 
$bb=explode (",",$cc); 



$f=$_POST['date']; 
$et=$_POST['event_title']; 
$ed=$_POST['event_date']; 
$ed1=$_POST['event_date1']; 


$j=$_POST['status']; 

    $showon=$_POST['showon']; 
for ($i = 0; $i < count($bb); $i++) { 

$pp= $bb[$i]; 



$insert="insert into gallery set  image='$pp',date='$f',event_title='$et',event_date='$ed',event_date1='$ed1',status='$j',sho wonpage='$showon'"; 

$res=mysqli_query($con,$insert); 
} 

그냥 등이 코딩을 적용
<td valign="top"> 
     <input type="file" id="paglink" maxlength="80" style="width:230px" name="files[]" multiple> 

</td> 

및 데이터베이스 페이지에서

, ... ... 당신과 함께 공유하고 있고 하나 t에서 원하는만큼 이미지를 업로드 할 수 있습니다 ime, .. 코딩 유지 :

+0

PHP 파일 제한이 20 인 경우이 코드로 50 개의 이미지를 업로드 할 수 있습니까? – abaracedo

+0

php.ini 파일에서 한계를 변경할 수 있습니다 .... –

+0

수정할 수없는 서버에서 로컬 호스트에서 작업하는 경우 변경할 수 있습니다 :/ – abaracedo

2

일부 jQuery를 사용하면 쉽게 얻을 수 있습니다. Ajax는 코딩하기가 어렵지 않습니다.

그러나 이미 PHP 백엔드의 종류를 제공하는 blueimp 같은 멋진 멀티 파일 업 로더가 있습니다.

+0

고마워요! 나는 그것을 점검 할 것이다 :) – abaracedo

0

FormData를 사용하여 가능하다고 들었습니다. 나는 그것을 사용한 적이 없지만 조사 할 수 있다면 당신은 알 것이다

+0

나는 그것을 알고 있었다. 나는 며칠 전에 FormData로 어떻게하는지 묻는 또 다른 질문을했고 그 해결책을 찾았습니다. 감사 – abaracedo

관련 문제