我在 CI 中有一个控制器,它允许我将文件上传到我的数据库。它在本地运行良好。我在 GoDaddy 上设置 CI,更改权限,更改数据库配置等。
现在,当我尝试上传文件时,我可以选择该文件,它会 100% 上传——但它不会保存。上传到的目录文件的权限是 777(现在用于测试)。我在 webdev 控制台中得到以下信息:
Error in event handler for (unknown): TypeError: Cannot read property 'state' of null
at CSRecorder.onQueryStateCompleted (chrome-extension://cplklnmnlbnpmjogncfgfijoopmnlemp/content_scripts/recorder.js:45:13)
at extensions::messaging:327:9
at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14)
at Event.dispatchToListener (extensions::event_bindings:386:22)
at Event.dispatch_ (extensions::event_bindings:371:27)
at Event.dispatch (extensions::event_bindings:392:17)
at dispatchOnMessage (extensions::messaging:294:22) extensions::event_bindings:375
GET http://mywebsite.com/index.php/assets/uploads/files/dark_bg.png 404 (Not Found) jquery-1.10.2.min.js:4
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
我也得到一个弹出窗口,上面写着"The page at mywebsite.com says: 6"
。
这是控制器(同样,它在我的本地 Windows 机器上工作):
public function photo_upload()
{
try{
$gc = new grocery_CRUD;
$gc->set_table('photography')
->set_subject('Image')
->required_fields('image_path')
->columns('image_path','image_name');
$gc->set_field_upload('image_path','assets/uploads/files');
$gc->unset_fields(array('image_date','image_extension'));
$gc->change_field_type('image_name','invisible');
$gc->callback_before_insert(array($this,'rename_image'));
$output = $gc->render();
$this->_example_output($output);
}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
}
function rename_image($post_array)
{
if (!empty($post_array)) {
//Remove image extension from image name
$img_name = preg_replace('/\.[^.]+$/', '', $post_array['image_path']);
//Remove codeigniter id from image name
$img_name = substr($img_name, 6);
$post_array['image_name'] = $img_name;
return $post_array;
}
}