CI 묻고 답하기

제목 upload관련 글입니다..
글쓴이 느림보 작성시각 2012/02/07 15:25:09
댓글 : 5 추천 : 0 스크랩 : 0 조회수 : 20380   RSS
안녕하세요 느림보입니다

ㅜㅜ 이번에 다중이미지 업로드를 위해서 jquery와 flash를 이용해서 업로드를 하는 uploadify를 사용중에 있습니다..

그런데 beta버전이라서 그런지... 문제점이 많네요

이것저것 고치다가 ㅜㅜ 치명적인 벽에 부딛쳤습니다..

바로 업로드시 folder생성문제지요...

업로드시에 folder를 생성 할수 있게 구문을 주었습니다..

..폴더는 어찌어찌 생성이 잘되서 이미지 업로드가 되는데

폴더만 생성하면 원래 넘어오던 callback함수부분이 실행이 안되네요 ㅜㅜ

다른분들은 폴더 생성후에 callback함수가 잘실행되시나요??

아래부분은 소스입니다.

view 부분입니다.
<script type="text/javascript" language="javascript">
  $(document).ready(function(){
     $('#whole').hide();    
     var id = $('#cookie').val();
     var date = $('#date').val();
     $("#upload").uploadify({
       'swf': '<?php echo base_url();?>js/uploadify.swf',
       'uploader': '<?php echo site_url('/product/product/uploadify');?>',
       'fileTypeExts': '*.jpg;*.jpeg;*.png;*.gif',
       'scriptAccess': 'always',
       'queueID' : 't',
       'multi': true,
       'folder'          : "/uploads/"+id+"/"+date+"/",
       'createFolder'  : true,
       'auto' : true,
       'buttonText' : '사 진 등 록',
       'uploadLimit' : 20,
       'width': '60',
       'height' : '20',
       'fileSizeLimit'   : 1*1024, // 1MB
       'fileTypeDesc'    : 'Image Files',
       'fileDesc' : 'JPG Image Files',
       'onUploadError' : function (a, b, c, d) {
         if (d.status == 404)
         alert('Could not find upload script.');
         else if (d.type === "HTTP")
         alert('error '+d.type+": "+d.status);
         else if (d.type ==="File Size")
         alert("파일은 1메가 이상 올리실수 없습니다.");
         else
         alert('error '+d.type+": "+d.text);
        },
       'onSelect': function ( file )
          {
           wrapWindowByMask();
          },
       'onUploadSuccess': function( file, data, response )
              {
                        $('#target').append("<div class='up_img' style='float:left;'><img width='100' height='100' src='/uploads/"+id+"/"+date+"/"+data+"'><input type='hidden' name='pro_image[]' value='"+data+"'></div>");
              }, 
       'onQueueComplete'  : function() //업로드 완료후 처리 callback 함수      
                         {  
                              $('#whole').fadeOut(1000);                 
                   }
     });    
  });
  function wrapWindowByMask()
  {                  
   $('#whole').show();
   var maskHeight = $(document).height();         
   var maskWidth = $(window).width();                 
   $('#whole').css({'width':maskWidth,'height':maskHeight, 'background-color':'grey'});             
   $('#whole').fadeIn(1000);         
   $('#whole').fadeTo("slow",0.8); 
  } 
 </script>
<div id="upload" >
</div>
<div id="t" style="display:none;">
</div>
controller부분입니다.
function uploadify()
 {
  $cookie = $this->input->cookie('username', 'true');
  $targetFolder = '/uploads/'; // Relative to the root
  $tempFile = $_FILES['Filedata']['tmp_name'];
  $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
  $targetFilename = $_FILES['Filedata']['name'];
  $ext = substr(strrchr($targetFilename,"."),1);
  $tmp_file = explode(' ',microtime());   //공백을 구분하여 마이크로초와 초를 구분
  $tmp_file[0] = substr($tmp_file[0],2,6); 
        $tmp_file[1] = substr($tmp_file[1],8,2);
        $cookie2 = substr($cookie, 0, 4);
        $file = "$tmp_file[1]$tmp_file[0]";
  $targetFilename = $_FILES['Filedata']['name'] = "$cookie2$file.$ext";
  $date = date("Y-m-d");
  if(!is_dir($targetPath.$cookie."/".$date))
  {
   mkdir($targetPath.$cookie, 0777);
   mkdir($targetPath.$cookie."/".$date, 0777);
  }
  $targetFile = rtrim($targetPath.$cookie."/".$date."/") . $targetFilename;
  if (!empty($_FILES)) 
  {
   // Validate the file type
   $fileTypes = array('jpg','jpeg','gif','png'); // File extensions
   $fileParts = pathinfo($_FILES['Filedata']['name']);
   if (in_array($fileParts['extension'],$fileTypes)) 
   {
    move_uploaded_file($tempFile,$targetFile);
    echo $targetFilename;
   } 
   else 
   {
    echo 'Invalid file type.';
   }
  }
 }

ㅜㅜ 외국포럼에도 뒤져봤는데 소스는 없구 다들 해결방안을 찾던거 같더라구요..흑
 다음글 워터마크 질문입니다. (2)
 이전글 HMVC 와 CI 2.10 사용질문입낟. (2)

댓글

변종원(웅파) / 2012/02/07 15:36:05 / 추천 0
ajax에서 뭐라고 넘어오는지 에러나 warning 등 메세지를 보세요.

성공할때 메세지가 아닌 다른게 화면에 출력되서 안넘어가는 걸겁니다.
변종원(웅파) / 2012/02/07 15:38:29 / 추천 0
 그리고  mkdir()에 세번째 파라미터로 true 주시면 /a/ 디렉토리만 있는 경우에
/a/b/c/ 순차생성할 필요없이 한번에 만들어줍니다.
느림보 / 2012/02/07 15:44:09 / 추천 0
헉...웅파님 완전 감사합니다 mkdir() true로 주니까....폴더 생성 후에도

callback함수까지 완벽하게 다 넘어 오는데요???

대...대단 하시옵니다..ㅜㅜ

;;;근본적인 문제까지 해결되었습니다..ㅎㅎ
변종원(웅파) / 2012/02/07 16:08:00 / 추천 0
그럼 폴더 생성이 안됐었던 거네요.
느림보 / 2012/02/07 16:28:49 / 추천 0
;;;아니에요 폴더는 정확히 제대로 생성됐는데 콜백함수만 안넘어오더라구요...

폴더가 생성 안됬다면 뭐가 문제가 생겼겠구나 했는데 폴더는 생성되고 이미지도 들어가버리는데

콜백함수만 안넘어 와서 진짜 깜짝 놀랬어요 ㅎㅎ;;;