CodeIgniter文件上传说"您没有选择要上传的文件"

时间:2015-08-26 12:49:10

标签: php .htaccess codeigniter

我查看过一系列相似的问题,似乎没有人能够得到答案。

我正在尝试在CodeIgniter中上传单个音频文件,但是继续获取​​"您没有选择要上传的文件"作为一个错误。

我的代码如下:

HTML

<form class="form-horizontal" id="mp3form" action="<?=base_url();?>comp/comp_sadsc/save_entry_music/<?= $comp_location.'/'.$entry_id; ?>" method="post" enctype="multipart/form-data">
    <div class="control-group" id="load-music">
        <label for="grouping_style" class="control-label">Load MP3 Music</label>
        <div class="controls">
            <input type="file" name="userfile" id="userfile" onchange="sadsc_select_music()">
        </div>
    </div>

    <div class="control-group" id="feedback" style="display:none;">
        <label for="grouping_name" class="control-label">Status</label>
        <div class="controls">
            <p id="responsemsg"></p>
        </div>
    </div>
</form>

<div class="progress progress-striped active" id="progressbar" style="display:none;">
    <div class="bar" style="width: 0%;"></div >
    <div class="percent">0%</div>
</div>

<div id="status"></div>

JS

var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
var progressbar = $('#progressbar');

$('#mp3form').ajaxForm({
    beforeSubmit : function(data) {
        check = data[0].value;
    },
    beforeSend: function() {
        progressbar.show();
        status.empty();
        var percentVal = '0%';
        bar.width(percentVal)
        percent.html(percentVal);
         return $('#mp3form').valid();
    },

    uploadProgress: function(event, position, total, percentComplete) {
        var percentVal = percentComplete + '%';
        bar.width(percentVal)
        percent.html(percentVal);
    },

    complete: function(xhr) {
        if (xhr.response == '"success"')
        {
            $.magnificPopup.close();
        }
        else
        {               
            alert("There was an error updating the music, please try again or contact the administrator. "+xhr.responseText);
        }
    }
});

CONTROLLER

public function save_entry_music($location, $location_entry_id)
{

$foldername = "./comps/sadsc/music/$location";

        if (!file_exists($foldername))
        {
            mkdir($foldername, 0777, true);
        }

        $config['upload_path'] = $foldername.'/';
        $config['allowed_types'] = 'mp3';
        $config['max_size'] = '0';
        $config['file_name'] = $location_entry_id.'.mp3';
        $config['overwrite'] = TRUE;

        $this->load->library('upload', $config);

        if (!$this->upload->do_upload())
        {
            $errors = array('error' => $this->upload->display_errors());
            $return = ' - error - ';
            foreach ($errors as $error)
            {
                $return .= $error.' ';
            }
        }
        else
        {
            $return = 'success';
        }

        $this -> output -> set_output(json_encode($return));
}

不确定这是否有帮助,但这是我的htaccess文件:

    RewriteEngine on
RewriteCond $1 !^(index\.php|img|css|vendor|data|fonts|files|js|comps|favicon\.ico)
RewriteRule ^(.+)$ index.php?$1 [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
#RewriteCond %{HTTP_HOST} - --website_url_removed--
#RewriteRule (.*) --website_url_removed--/$1 [R=301,L]

我真的希望它只是我想念的小事。

0 个答案:

没有答案