Codeigniter,GroceryCRUD,GoDaddy - 文件上传错误

时间:2013-12-10 19:13:11

标签: php linux codeigniter grocery-crud

我在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;
        }
    }

2 个答案:

答案 0 :(得分:1)

您是否100%确定目录是否存在以及您指向的image_path是否存在?

$gc->set_field_upload('image_path','assets/uploads/files');

您可以为此设置绝对路径:

$gc->set_field_upload('image_path',BASEPATH.'assets/uploads/files');

你能告诉我你的CI错误日志说的是什么吗?在application / logs / log中 - * .php 我不明白你得到的错误是错误弹出似乎不是来自这段代码。我期待弹出这条消息:

show_error($e->getMessage().' --- '.$e->getTraceAsString());

但你得到:"The page at mywebsite.com says: 6"

答案 1 :(得分:1)

使用getcwd()检查当前工作目录。您是否从子目录(例如mydomain.com/dev)开发本地计算机上的站点,现在在您的实际主机上从mydomain.com/这样的根目录运行它?如果是,你的

$gc->set_field_upload('image_path','assets/uploads/files');

实际上可能需要一个额外的/在路径中..如果没有,请告诉我们输出:

echo getcwd()。 “
”; 以及从任何ftp客户端到资产/上传/文件的完整路径。 在foto_upload方法中执行getcwd()命令,以确保您看到CI当前正在使用的实际路径。