2009-11-21 3 views
0

Uploadify를 사용하여 이미지를 업로드하고 있습니다. 이제 올바른 업로드 경로를 얻어야합니다.javascript/jQuery와 PHP 결합

I가 다음 코드/스크립트

<?php 
    $uploadifyPath = get_bloginfo('url') . '/wp-content/plugins/uploadify/'; 
    $galleryPath = "'".getGalleryURL('1620')."'"; // <--- 1620 is inputed by me. 
    ?> 

    <input id="galleryID" type="hidden" value="1620" name="galleryID"/> 
    <input id="fileInput" name="fileInput" type="file" /> 

    <script type="text/javascript">// <![CDATA[ 
    $(document).ready(function() { 
     $('#fileInput').uploadify({ 
      'uploader' : '<?php echo $uploadifyPath ?>uploadify.swf', 
      'script' : '<?php echo $uploadifyPath ?>uploadify.php', 
      'cancelImg' : '<?php echo $uploadifyPath ?>cancel.png', 
      'auto'  : true, 
      'folder' : <?php echo $galleryPath ?> 
     }); 
    }); 
    // ]]></script> 

어떻게, jQuery를 함께 내 기능 getGalleryURL()에 galleryID의 값과 입력을받을 수 있나요?

또는 ...이 작업을 수행하는 더 좋은 방법은 무엇입니까 ??

+0

jquery가 약간의 작업을 할 때 이미 요청이 서버에서 반환되었으며 PHP는 이미 작업을 완료했습니다. 1620을 galleryID 입력에 어떻게 집어 넣고 있습니까? – Galen

+0

텍스트 검색 상자에서 Autocomplete를 사용할 때 galleryID가 jQuery에서 값을 가져옵니다. – Steven

답변

1

수 없습니다. PHP 코드가 웹 서버에서 실행됩니다. 그런 다음 HTML/CSS/JS 코드가 브라우저로 전송되어 javascript가 실행됩니다.

Javascript/PHP 통신이 필요한 경우 jQuerys AJAX 기능을 사용해야합니다.

+0

1

jQuery를 통해 AJAX 호출을 수행하여 PHP가 galleryID를 알 수 있도록하고 uploadify를로드하기 위해 콜백을 사용합니다.

0

이 과제를 완전히 해결하려면 지금 당장 작업하고있는 프로젝트에 대해 알아야했습니다.

내가 온 것은 더 간단했다. 스크립트 전에 HTML에서 변수를 반향시킨 다음 jQuery가 데이터 속성에서 변수를 가져올 수있다.

아직 아래 코드를 테스트하지는 않았지만 비슷한 것으로 해결할 수 있다고 상상해보십시오. 행운을 빕니다!

<div class="marker" data-path="<?php echo get_bloginfo('url') . '/wp-content/plugins/uploadify/'; ?>" data-url="<?php echo getGalleryURL('1620'); ?>" style="display:none;"></div> 

<input id="galleryID" type="hidden" value="1620" name="galleryID"/> 
<input id="fileInput" name="fileInput" type="file" /> 


<script type="text/javascript">// <![CDATA[ 
    $(document).ready(function() { 


     var path = $('.marker').data('path'); 
     var url = $('.marker').data('url'); 

     $('#selector').uploadify({ 
      'uploader' : url + '/uploadify.swf', 
      'script' : url + '/uploadify.php', 
      'cancelImg' : url + '/cancel.png', 
      'auto'  : true, 
      'folder' : path 
     }); 
    }); 

    // ]]> 
</script>