2017-05-02 3 views
0

갤러리에서 서버로 이미지를 업로드하고 싶습니다. 나는 이미지 업로드에 성공하지만, 나는 단지 1 파일을 업로드 할 수있다. 내가 2 파일을 업로드하면 두 번째 파일이 업로드됩니다. 첫 번째 파일은 업로드되지 않습니다. 또는 두 번째 이미지 파일을 편집하고 업로드하면 첫 번째 이미지 파일이 두 번째 이미지 파일로 대체됩니다.파일 업로드시 오류 발생

$imagePath  = IMAGE_PATH_FOR_TIM_THUMB.'/'.STUDY_MATERIAL_DIR.'/'; 
    if (!empty($_POST)) 
    { 
     $this->loadModel('StudyMaterial'); 
     if($_POST['type'] != 'delete') 
     { 
      $shift = array(); 
      if($_POST['type'] == 'edit') 
      { 
       $shift['StudyMaterial']['id'] = $_POST['study_material_id']; 
      } 
      $shift['StudyMaterial']['user_id'] = $_POST['user_id']; 
      $shift['StudyMaterial']['standard_id'] = $_POST['standard_id']; 
      $shift['StudyMaterial']['subject_id'] = $_POST['subject_id']; 
      $shift['StudyMaterial']['topic_id'] = $_POST['topic_id']; 
      $shift['StudyMaterial']['lesson_id'] = $_POST['lesson_id']; 
      $shift['StudyMaterial']['name'] = $_POST['name']; 
      $shift['StudyMaterial']['description'] = $_POST['description']; 

      $this->StudyMaterial->save($shift); 
      $study_material_id = $this->StudyMaterial->id; 

      if(isset($_FILES['study_material_file']) && !empty($_FILES['study_material_file']) && ($_FILES['study_material_file']['error'] == 0)) 
      { 
       $name = $_FILES['study_material_file']['name']; 
       $ext = substr(strrchr($name, "."), 1); 
       $only_name = $name . "_" . time(); 
       $filename = 'topic_file_'.microtime(true).'.'.strtolower($ext); 
       $original = STUDY_MATERIAL_DIR . "/" . $filename; 
       $file_type = $_POST['file_type'];   
       if($file_type == 'video') 
       { 
        if(strtolower($ext) == 'mov') 
        { 
         $original = STUDY_MATERIAL_DIR . "/" . $filename; 
         @move_uploaded_file($_FILES["study_material_file"]["tmp_name"], $original); 
         $new_filename = $only_name. '.mp4'; 
         $srcFile = STUDY_MATERIAL_DIR . "/" . $filename; 
         $destFile = STUDY_MATERIAL_DIR . "/" . $new_filename;     
         exec('ffmpeg -i '.$srcFile.' -f mp4 -s 320x240 '.$destFile.'');   
         if($_POST['type'] == 'edit') 
         { 
          $checkAlready = $this->StudyMaterial->find('first',array('conditions'=>array('StudyMaterial.id'=>$_POST['study_material_id'])));   
          $image = $checkAlready['StudyMaterial']['file_name']; 
          if($image && file_exists(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image)) 
          { 
           @unlink(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image); 
          } 
         } 
         $this->StudyMaterial->saveField('file_name',$filename,false); 
         $this->StudyMaterial->saveField('type',$file_type,false); 
        } 
        else 
        { 
         @move_uploaded_file($_FILES["study_material_file"]["tmp_name"], $original); 
         if($_POST['type'] == 'edit') 
         { 
          $checkAlready = $this->StudyMaterial->find('first',array('conditions'=>array('StudyMaterial.id'=>$_POST['study_material_id'])));   
          $image = $checkAlready['StudyMaterial']['file_name']; 
          if($image && file_exists(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image)) 
          { 
           @unlink(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image); 
          } 
         } 
         $this->StudyMaterial->saveField('file_name',$filename,false); 
         $this->StudyMaterial->saveField('type',$file_type,false); 
        } 
       } 
       else 
       {   
        @move_uploaded_file($_FILES["study_material_file"]["tmp_name"], $original); 
        if($_POST['type'] == 'edit') 
        { 
         $checkAlready = $this->StudyMaterial->find('first',array('conditions'=>array('StudyMaterial.id'=>$_POST['study_material_id'])));   
         $image = $checkAlready['StudyMaterial']['file_name']; 
         if($image && file_exists(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image)) 
         { 
          @unlink(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image); 
         } 
        } 
        $this->StudyMaterial->saveField('file_name',$filename,false); 
        $this->StudyMaterial->saveField('type',$file_type,false); 
       } 
      } 
      else 
      { 
       if($_POST['type'] == 'edit') 
       { 
        $this->StudyMaterial->id = $_POST['study_material_id']; 
        $this->StudyMaterial->saveField('file_name','',false); 
        $this->StudyMaterial->saveField('type','',false); 
       }     
      } 
      if($_POST['type'] == 'edit') 
      { 
       $responseData = array(
        'status' => 1, 
        'message' => "Study Material updated successfully." 
       ); 
      } 
      else 
      { 
       $responseData = array(
        'status' => 1, 
        'message' => "Study Material added successfully." 
       ); 
      } 
     } 

는 웹 서비스 또는 안드로이드에 문제가 webservicecontroller.php입니까? 이것은 당신이 당신의 열을 업데이트 서버 측 add_material.java

private void selectImage() { 

    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    intent.setType("image/*"); 
    getActivity().startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); 
} 

public String getRealPathFromURI(Uri contentUri) { 
    String[] proj = {MediaStore.Images.Media.DATA}; 
    Cursor cursor = getActivity().managedQuery(contentUri, proj, null, null, null); 
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
    cursor.moveToFirst(); 
    return cursor.getString(column_index); 
} 
+0

업로드 코드가 없습니다. 그래서 우리는 무엇을 말할 수 있을까요? – greenapps

+0

두 개 또는 두 개의 파일을 한 번에 업로드하면 명확하지 않습니다. – greenapps

답변

0

문제 확인하시기 바랍니다 데이터베이스 쿼리입니다.

+0

나는 데이터베이스를 점검했는데, 그 열은 옳았다. 이전 이미지를 대체하지 않고 파일 이미지를 업로드하는 방법? – muffin

+0

나는 서버에 이미지를 업로드 할 때마다 같은 이름을 사용하고 있다고 생각한다. 서버의 이미지 업로드에 다른 이름을 사용한다. –

+0

은 @unlink 기능 때문인가? – muffin

관련 문제