我有点头疼试图让Uploadify与Codeigniter合作。基本上我要做的就是上传多个文件,然后运行db查询将其详细信息添加到我的数据库中。我将在稍后添加更复杂的代码(比如获取EXIF / IPTC数据),但是现在我只需要它来获取文件名并在每张照片上传后插入数据库。
麻烦的是我收到HTTP 302错误。我设定了这个:
$config['sess_match_useragent'] = FALSE;
我还在我的.htaccess文件中添加了以下内容:
SecFilterEngine Off
SecFilterScanPOST Off
但它导致整个网站停止工作,引发了“内部服务器错误”。
我真的想让uploadify工作,这很棒,只是与Codeigniter有点噩梦!
我的代码如下:
在我看来输入:
<input id="fileInput" name="fileInput" type="file" />
<script type="text/javascript">
$(document).ready(function() {
$("#fileInput").uploadify({
'uploader' : '<?php echo base_url()?>assets/uploadify/uploadify.swf',
'script' : '<?php echo site_url()?>/upload/do_upload/',
'cancelImg' : '<?php echo base_url()?>assets/uploadify/cancel.png',
'fileExt' : '*.jpg;*.jpeg',
'folder' : 'assets/photos/highres',
'auto' : true,
'multi' : true,
'onError' : function (event,ID,fileObj,errorObj) {
alert(errorObj.type + ' Error: ' + errorObj.info);
}
}); });
</script>
我的控制器:
public function do_upload()
{
// check for login, if logged in
if($this->session->userdata('logged_in') == "1")
{
$config['upload_path'] = 'assets/photos/highres/';
$config['allowed_types'] = 'jpg';
$config['max_size'] = '1000000';
$config['overwrite'] = FALSE;
$config['remove_spaces'] = TRUE;
$config['encrypt_name'] = FALSE;
$this->load->library('upload', $config);
if(! $this->upload->do_upload('Filedata'))
{
echo $this->upload->display_errors();
}
else
{
$errors = $this->upload->display_errors();
$upload_info = $this->upload->data();
// Insert file information into database
$data = array(
'id' => NULL,
'filename' => $upload_info['file_name']
);
$this->db->insert('photos', $data);
}
}
else
{
// redirect to signin page if not logged in
redirect('signin');
}
}
非常感谢任何帮助!
答案 0 :(得分:2)
更改文件/application/config/mimes.php 添加
'application/octet-stream'
在
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpe' => array('image/jpeg', 'image/pjpeg'),
'png' => array('image/png', 'image/x-png'),
最后像这样的哑剧
'jpeg' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpg' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpe' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'png' => array('image/png', 'image/x-png', 'application/octet-stream'),