在Localhost上使用带有Wordpress的Uploadify - 不加载

时间:2012-03-05 01:41:39

标签: jquery wordpress uploadify

全部, 我已将JS文件包含在我需要的Wordpress主题中。然后我创建了以下页面:

<?php
$js_path_uploadify = ABSPATH."wp-content/uploadify.swf";
$js_path_script = ABSPATH."wp-content/uploadify.php";
$cancel_path = ABSPATH."wp-content/cancel.png";
$check_path = ABSPATH."wp-content/check.php";
$uploads_path = ABSPATH."wp-content/uploads";
?>
<script type="text/javascript">
$(document).ready(function() {
  $('#custom_file_upload').uploadify({
    'uploader'  : '<?php echo $js_path_uploadify; ?>',
    'script'    : '<?php echo $js_path_script ; ?>',
    'cancelImg' : '<?php echo $cancel_path; ?>',
    'folder'    : '<?php echo $uploads_path; ?>',
    'auto'      : false,
    'multi'     : true,
    'fileExt'        : '*.jpg;*.gif;*.png',
    'fileDesc'       : 'Image Files (.JPG, .GIF, .PNG)',
    'buttonText': 'Add Files',
    'checkScript': '<?php echo $check_path; ?>',
    'displayData': 'speed',
    'onComplete': function(a, b, c, d, e){ alert(d);},
    'onAllComplete': function(event,data){
            //something here
     },
        'onError': function(event,data){
            //something here
        }
  });

  $("#upload_files").click(function(){
      alert("it is here");
    $('#custom_file_upload').uploadifyUpload();
  });
});
</script>

</head>
<body>
<div id="status-message">Select some files to upload:</div>
<input id="custom_file_upload" type="file" name="Filedata" />
<div id="error-message"></div>
<input type="button" id="upload_files" value="Upload Files">

当我这样做时它看起来不错,但是当我检查我的console.log时出现以下错误。错误是:

不允许加载本地资源:file:/// D:/My%20Documentsxampphtdocs%0Bendor_wordpress/wp-content/uploadify.swf

有关此问题或如何解决问题的任何想法?

由于

1 个答案:

答案 0 :(得分:1)

您不希望在此处使用ABSPATH

错误:

  

不允许加载本地资源:file:/// D:/My%20Documentsxampphtdocs%0Bendor_wordpress/wp-content/uploadify.swf

解释说您正在尝试通过本地文件系统加载该swf。你不想那样做。相反,您希望它指向您的网络服务器上的位置。

更重要的是,您不应将uploadify文件直接放入wp-content中。理想情况下,它们应放在主题的文件夹中。我已经在随后的代码中更改了uploadify文件的位置。您可以在主题文件夹中移动它们(确保相应地更新变量!)

<?php
$template_url = get_bloginfo('template_url');
$upload_dir = wp_upload_dir();

$js_path_uploadify = $template_url."uploadify/uploadify.swf";
$js_path_script = $template_url."uploadify/uploadify.php";
$cancel_path = $template_url."uploadify/img/cancel.png";
$check_path = $template_url."uploadify/check.php";
$uploads_path = $upload_dir['path'];
?>

我之前从未使用过此脚本。这只是一个通用指南,应该可以帮助您进一步调试/解决您的问题。如果您需要,可以参考wp_upload_dirbloginfo

相关问题