2012-03-05 50 views
0

全部, 我已經將JS文件包含在我需要的Wordpress主題中。然後,我創建了以下頁面:在本地主機上使用Uploadify和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。錯誤是:

不允許加載本地資源:文件:/// d:/My%20Documentsxampphtdocs%0Bendor_wordpress/wp-content/uploadify.swf

對什麼是錯這個或如何任何想法要解決這個問題?

感謝

回答

1

你不想在這裏使用ABSPATH

錯誤:

Not allowed to load local resource: file:///D:/My%20Documentsxampphtdocs%0Bendor_wordpress/wp-content/uploadify.swf

解釋說,你想通過您的本地文件系統加載的SWF。你不想這樣做。相反,您希望它指向您的Web服務器上的位置。

更重要的是,您不應該將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

相關問題