无法在PHP Wordpress中上传文件

时间:2013-01-24 18:40:00

标签: php jquery ajax wordpress file-upload

我正在尝试在我的主题文件中插入PHP文件上传代码在wordpress.Everything工作正常,但它不上传文件。我认为我在ajax部分给它的网址不起作用。这是我的代码。

<?php
$uploaddir = '/uploads/'; 
$file = $uploaddir . basename($_FILES['uploadfile']['name']); 

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
  echo "success"; 
} else {
    echo "error";
}
?>

和HTML

<script type="text/javascript" >
    $(function(){
        var btnUpload=$('#upload');
        var status=$('#status');
        new AjaxUpload(btnUpload, {
            action: 'upload-file.php',
            name: 'uploadfile',
            onSubmit: function(file, ext){
                 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
                    // extension is not allowed 
                    status.text('Only JPG, PNG or GIF files are allowed');
                    return false;
                }
                status.text('Uploading...');
            },
            onComplete: function(file, response){
                //On completion clear the status
                status.text('');
                //Add uploaded file to list
                if(response==="success"){
                    $('<li></li>').appendTo('#files').html('<img src="./uploads/'+file+'" alt="" /><br />'+file).addClass('success');
                } else{
                    $('<li></li>').appendTo('#files').text(file).addClass('error');
                }
            }
        });

    });
</script>
<div id="upload" ><span>Upload File<span></div><span id="status" ></span>

        <ul id="files" ></ul>

当我试图看到响应时,它向我展示了简单的html raw。 任何可以帮助我的人。在localhost上运行正常 感谢

0 个答案:

没有答案