Codeigniter, GroceryCRUD, GoDaddy - file upload error

1.5k views Asked by At

I have a controller in CI which allows me to upload files to my database. It works fine locally. I setup CI on GoDaddy, changed permissions, changed database configs etc.

Now when I try to upload a file, I can select the file and it gets to 100% uploaded -- but it doesn't save. Permissions on the directory files get uploaded to are 777 (for testing right now). I get the following in the webdev console:

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. 

I also get a popup that says "The page at mywebsite.com says: 6".

Here is the controller (again, it's working on my local Windows machine):

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

There are 2 answers

1
Flashin On

Are you 100% sure the directory exists and the image_path you are pointing to exists?

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

You could set an absolute path for that:

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

And can you tell me what your CI error logs say? In application/logs/log-*.php What i don't understand about the error you are getting is the error popup doesn't seem to be coming from this piece of code. I was expecting this message to popup:

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

But instead you get: "The page at mywebsite.com says: 6".

0
Stijn van Grinsven On

Check your current working dir with getcwd(). Did you develop the site on your local machine from a subdirectory eg mydomain.com/dev and now on your actual hosting you are running it from a root directory like mydomain.com/ ? If it is, your

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

might actually need an additional / in the path.. If not, show us the output of:

echo getcwd() . "
"; and the full path from any ftp client to the assets/uploads/files. Execute the getcwd() command in the foto_upload method to make sure you are seeing the actual path CI is currently working from.