我正在尝试将 Codeigniter 与称为 redactor js 的所见即所得编辑器一起使用。基本上,我想要完成的可以在这里找到:http: //imperavi.com/redactor/docs/images/
这似乎很容易,但我无法让它工作。我的控制台中不断收到 500 错误。这是我当前的编码:
编辑器js:
<script type="text/javascript">
$(document).ready(
function() {
$('#redactor_content').redactor({
imageUpload: 'user/simple_upload'
});
});
</script>
处理上传的 PHP 类:
class User extends MX_Controller
{
public function simple_upload()
{
$dir = './uploads/user_post_uploads/';
$_FILES['file']['type'] = strtolower($_FILES['file']['type']);
if ($_FILES['file']['type'] == 'image/png' || $_FILES['file']['type'] ==
'image/jpg' || $_FILES['file']['type'] == 'image/gif' || $_FILES['file']['type'] ==
'image/jpeg' || $_FILES['file']['type'] == 'image/pjpeg') {
// setting file's mysterious name
$filename = md5(date('YmdHis')) . '.jpg';
$file = $dir . $filename;
// copying
copy($_FILES['file']['tmp_name'], $file);
// displaying file
$array = array('filelink' => base_url() . 'uploads/user_post_uploads/' . $filename);
echo stripslashes(json_encode($array));
}
}
}
我基本上创建了一个类似于示例的控制器函数,然后我在 redactor 函数中引用它。似乎不起作用......我在控制台中不断收到这些错误:
POST http://localhost/appname/user/simple_upload 500 (Internal Server Error) - /improciety/user/simple_upload:1
Uncaught TypeError: Cannot read property '0' of null - redactor.js:3100
Redactor.uploadLoaded - redactor.js:3100
g - jquery.js:2
f.event.dispatch - jquery.js:3
h.handle.i - jquery.js:3