views:

224

answers:

2

I'm using Uploadify to upload an image. Now I need to get the correct upload path.

I have the following code / script:

  <?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>

How can I, with jQuery, get the value of galleryID and input it into my function getGalleryURL() ?

Or... is there a better way to do this??

+1  A: 

You can't. You're PHP code is executed on the webserver. Then, the HTML/CSS/JS code is transmitted to the browser, where javascript is executed.

If you need Javascript/PHP communication, you will have to use jQuerys AJAX functionality.

x3ro
Note how I'm using PHP inside the <script> tags. So I'm already mixing the two.
Steven
No, you aren't, actually. As I said, PHP is executed on the webserver, and Javascript in the client browser, therefor, Javascript will never be able to tell if some value came out of a PHP function or it was hardcoded or whatever. You should really try to understand the difference between server-side and client-side languages, as that would answer all your questions on this matter.
x3ro
A: 

Do an AJAX call via jQuery to let PHP know the galleryID and then use it's callback to load uploadify.

Blair McMillan