我有一個音頻上傳功能,可以上傳用戶選擇的音樂。 但是,有些文件顯示它們的格式正確,但上傳者說我試圖上傳的文件不正確。PHP文件上傳不允許格式在allowed_types
我笨的配置如下:
$config['allowed_types'] = 'mp3|wav|m4a|wma';
我使用以下方法來獲取音頻格式:
$ext = end(explode(".", $_FILES["userfile"]["name"]));
當我回聲$轉出,它顯示的MP3,但上傳帶有此錯誤的退貨:
The filetype you are attempting to upload is not allowed.
當我使用音頻轉換器(我使用Freemake)將fi再次mp3,上傳者允許該文件,所以我不知道該文件是否顯示MP3,但仍然是文件系統上的舊格式。
任何信息/幫助將不勝感激。
Thanx提前。
UPDATE
我的PHP上傳代碼如下所示:
$entry_num = $this -> input -> post('entry_num');
$location = $this -> input -> post('location');
$foldername = "./music/$location";
if (!file_exists($foldername))
{
mkdir($foldername, 0777, true);
}
$ext = end(explode(".", $_FILES["userfile"]["name"]));
$config['upload_path'] = $foldername.'/';
$config['allowed_types'] = 'mp3|wav|m4a|wma';
$config['file_name'] = $entry_num.'.'.$ext;
$config['overwrite'] = TRUE;
$this -> load -> library('upload', $config);
if (!$this -> upload -> do_upload('userfile'))
{
$errors = array('error' => $this -> upload -> display_errors());
$return = implode(" ",$errors);
}
我的視圖看起來是這樣的: HTML
<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">
</div>
</div>
的JavaScript
(function()
{
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
var progressbar = $('#progressbar');
$('#mp3form').ajaxForm({
beforeSubmit : function(data) {
check = data[1].value;
},
beforeSend: function() {
progressbar.show();
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
if (percentComplete > 10)
{
percent.show();
}
},
complete: function(xhr) {
if (xhr.responseText == '"success"')
{
$('#modal-footer-content').html("<button class='btn btn-default' onclick='cancel()'>Close</button>");
$('#modal-text').html('Music sucessfully uploaded, thank you.');
//Insert code to update table row with music play back
comp_code = '<?=$entry_details['location'];?>';
entry_num = <?=$entry_details['entry_num'];?>;
$('').postJsonCheck('comp/get_entry_details', {comp_code:comp_code, entry_num:entry_num},function(data){
var entry_details = data.entry_details;
var content = '<div style="float:left;padding-top:5px;"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="15" height="15"><PARAM NAME=movie VALUE="<?=base_url();?>img/audioplay.swf?file=<?=base_url();?>comps/music/'+entry_details["location"]+'/'+entry_details["entry_num"]+'.'+entry_details["music_ext"]+'&auto=no&sendstop=yes&repeat=0&buttondir=<?=base_url();?>img/audiobuttons/green_small&bgcolor=0xffffff&mode=playstop"><PARAM NAME=quality VALUE=high><PARAM NAME=wmode VALUE=transparent><embed src="<?=base_url();?>img/audioplay.swf?file=<?=base_url();?>comps/music/'+entry_details["location"]+'/'+entry_details["entry_num"]+'.'+entry_details["music_ext"]+'&auto=no&sendstop=yes&repeat=0&buttondir=<?=base_url();?>img/audiobuttons/green_small&bgcolor=0xffffff&mode=playstop" quality=high wmode=transparent width="15" height="15" align="" TYPE="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object></div><a href="#" onclick="edit_entry_music(\'<?= $entry_details['location']; ?>\', \'<?= $entry_details['entry_num']; ?>\');return false;" style="margin-left:5px; padding-top:15px;"><i class="fa fa-music"></i></a>';
if (entry_details.audio_status == 'Error')
{
content = '<div style="float:left;padding-top:2px; color: red; padding-right: 7px;"><i class="fa fa-exclamation-triangle" data-original-title="Music to long! Length: '+entry_details.length_text+', Max Length: '+entry_details.max_length_text+'" data-placement="top" data-toggle="tooltip"></i></div>'+content;
var notification = {};
notification["type"] = 'error';
notification["text"] = 'Music added is too long!';
notification["title"] = 'Error';
show_notification(notification)
}
$('#edit_<?= $entry_details['entry_num']; ?>_music').html(content);
$('[data-toggle="tooltip"]').tooltip({'placement': 'top'});
});
}
else
{
str = xhr.responseText;
var res = str.slice(4, -6);
$('.music_upload_error').html(res);
$('.music_upload_error').show();
//alert('There was an error updating the music, please try again or contact the administrator. '+xhr.responseText);
}
}
});
})();
發表您完全上傳相關代碼。你在使用CodeIgniter嗎? – jagad89
對不起,忘了提,是的,我使用的是CodeIgniter,我已經添加了完整的PHP代碼 –
你的視角是什麼? – jagad89