2013-03-23 7 views
0

Uploadify를 사용하여 파일을 업로드 할 폴더를 사용자가 선택할 수있는 방법을 찾고 있습니다. 나는 자바 스크립트 코드를 가지고 있지만 마지막 비트를 제외하고는 모두 작동한다. 네가 원한다면 나는 그것을 모두 보여줄 수 있지만 나는 그 것이 문제가 아니라고 확고하게 믿는다. 이 코드는 document.ready에 싸여()되어업로드 오류 받기 : uploadify 설정이 아닌 함수

$("#file_upload").uploadify({ 
     'buttonText' : 'Upload New Files', 
     'height'  : 30, 
     'swf'   : 'uploadify/uploadify.swf', 
     'uploader'  : 'uploadify/uploadify.php', 
     'width'   : 120, 
     'folder'  : $('#folder').val(), 
     'auto'   : true, 
     'multi'   : true, 
     'onUploadComplete' : function(file) { 
      location.reload(); 
     } 
    }); 

    $("#folder").change(function() { 
     var path = "/" + $(this).val(); 
     $('#file_upload').uploadifySettings("scriptData", {'folder': path }); 
     alert(path); 
    }); 

:

여기 내 코드입니다.

어떤이 코드가하는 일은

  1. 사용자가 드롭 다운은 #folder의 값을 (변경하는 경우 변경하는 uploadify 기능의 값 "폴더를"되세요 uploadify 기능을 초기화입니다).

선택 상자를 클릭해도 아무런 변화가 없습니다. 줄을 주석으로 처리하는 경우 :

$('#file_upload').uploadifySettings("scriptData", {'folder': path }); 

경고를 받으면 아무 것도하지 않습니다.

나는 방화범을 상담하고 나는 다음과 같은 오류지고 있다고 보았다

TypeError: $(...).uploadifySettings Not A Function 

논리적으로, 나는 이것이 내가 uploadify이 페이지에 연결되지 않습니다이없는 것을 의미 말할 것입니다. 그러나 파일을 업로드하면 업로드되므로 업로드되어 작동합니다.

은 여기 내 HTML/PHP입니다 :

<h3>Your Uploaded Files</h3> 
    <input type="file" name="file_upload" id="file_upload"> 
    <span style="margin: 5px 10px 0 0; float: left;">to</span> 
    <select id="folder"> 
     <?php 
     echo '<option value="'.$directory.'">Downloads</option>'; 
     $friendlyDir; 
     foreach(glob('downloads/*', GLOB_ONLYDIR) as $dir) { 
      $friendlyDir = str_replace("downloads/","",$dir); 
      echo '<option value="'.$dir.'">'.ucfirst(strtolower($friendlyDir)).'</option>'; 
     } 
     ?> 
    </select> 
    <div id="file_viewer"></div> 

HTML/PHP가 잘 작동하지만 난 너무 당신은 트리거와 같은 무엇을 볼 수 있었다 그것을 포함 거라 생각 했어요.

누군가가이 문제를 조사 할 수 있다면 감사 할 것입니다. 크로스 브라우저 테스트를하지는 않았지만 사용중인 브라우저는 Firefox 19.0.2입니다.

감사합니다.

답변

1

나는 그것에 uploadify 기능 파일에이 일을 결국 :

var path; 
    $("#file_upload").uploadify({ 
     'buttonText' : 'Upload New Files', 
     'height'  : 30, 
     'swf'   : 'uploadify/uploadify.swf', 
     'uploader'  : 'uploadify/uploadify.php', 
     'width'   : 120, 
     'folder'  : $('#folder').val(), 
     'auto'   : true, 
     'multi'   : true, 
     'folder'  : path, 
     'onUploadStart' : function(file) { 
      $('#file_upload').uploadify("settings", 'formData', {'folder' : path}); 
     }, 
     'onUploadSuccess' : function(file, data, response) { 
      //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data); 
      location.reload(); 
     } 
    }); 

    $("#folder").change(function() { 
     path = "/" + $(this).val(); 
    }); 

그리고 uploadify.php에 나는이 그것을 변경 :

//$targetFolder = '/file/downloads'; // Relative to the root 
$targetFolder = "/file".$_POST['folder']; 

if (!empty($_FILES)) { 
$tempFile = $_FILES['Filedata']['tmp_name']; 
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; 
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; 

// Validate the file type 
$fileTypes = array('jpg','jpeg','gif','png','pdf','doc','docx'); // File extensions 
$fileParts = pathinfo($_FILES['Filedata']['name']); 

if (in_array($fileParts['extension'],$fileTypes)) { 
    move_uploaded_file($tempFile,$targetFile); 
    echo $targetFolder; 
} else { 
    echo 'Invalid file type.'; 
} 
} 

을 그리고 지금은 작동합니다 : D