0

我正在使用 Uploadify 上传图片。现在我需要获取正确的上传路径。

我有以下代码/脚本:

  <?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 获取 galleryID 的值并将其输入到我的函数中getGalleryURL()

或者......有没有更好的方法来做到这一点?

4

3 回答 3

1

你不能。您的 PHP 代码在网络服务器上执行。然后,HTML/CSS/JS 代码被传输到执行 javascript 的浏览器。

如果您需要 Javascript/PHP 通信,则必须使用 jQuerys AJAX 功能。

于 2009-11-21T00:28:31.517 回答
1

通过 jQuery 进行 AJAX 调用,让 PHP 知道 galleryID,然后使用它的回调来加载 uploadify。

于 2009-11-21T00:59:23.950 回答
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>
于 2014-06-15T17:24:28.033 回答