Welcome Guest, Not a member yet? Register   Sign In
File not uploading live hosting. help? :)
#1

(This post was last modified: 10-07-2023, 07:44 AM by xsPurX.)

I had this working fine on localhost, but since I put the folder structure outside public_html, I had to change the path to the upload directory. So I made a writable/uploads folder in public_html. The problem is it doesn't seem to upload, and my database just gives fillled with only part of the file path, with no filename. Sorry for all the posts, I'm used to CI2. and been away for awhile. so I skipped CI3. and a lot has changed!
PHP Code:
rules = [
                    'name' => 'required|max_length[100]',
                    'userfile' => [
                        'label' => 'Image File',
                        'rules' => [
                            'is_image[userfile]',
                            'mime_in[userfile,image/jpg,image/jpeg,image/gif,image/png,image/webp]',
                            'max_size[userfile,500000]',
                            'max_dims[userfile,500000,500000]',
                        ],
                    ],
            ];
            if (! $this->validate($rules))
                {
                $request = \Config\Services::request();
                $this->data['error'] = ['errors' => $this->validator->getErrors()];
                $this->data['heading'] = 'Add Article';
                $this->data['layouts'] = $this->PageAdminModel->get_layouts();
                $this->data['categories'] = $this->BlogAdminModel->get_categories();
                $this->data['groups'] = $this->PageAdminModel->get_groups();
                $this->data['w_locations'] = $this->PageAdminModel->get_widget_locations();
                $page_container 'layout_blank';
                $template_path '/themes/admin/layouts/';
                $layout $template_path$page_container;
                $this->data['page'] = $template_path '/BlogAdmin/addarticle';
                return view($layout$this->data);
                }
            else
                {
                $request = \Config\Services::request();
                $img $this->request->getFile('userfile');
                if($img == '')
                    {
                    $file '';
                    }
                else
                    {
                    if (! $img->hasMoved()) 
                        {
                        $filepath $_SERVER['DOCUMENT_ROOT'] . '/writable/uploads/' $img->store();

                        $userfile = ['uploaded_fileinfo' => new File($filepath)];
                        $file_name explode ('/'$userfile['uploaded_fileinfo']);
                        $file $file_name[1] . '/' $file_name[2];
                        }
                    }  
                $data 
= [
                    'name' => strip_tags($this->request->getPost('name')),
                    'url_name' => strip_tags(url_title($this->request->getPost('name'))),
                    'text' => $this->request->getPost('text'),
                    'userfile' => $file,
                    'container_name' => $this->request->getPost('container_name'),
                    'active' => $this->request->getPost('active'),
                ];
                $this->db->table('blog')
                ->insert($data); 


Edit.... now it is somehow uploading the files to the directory above public-html. I don't understand why its uploading there, cause I have the correct path listed above. Somehow ci is saving the files in an unaccessable folder.. Any ideas?

I had to do this below. it works. Smile

PHP Code:
filepath = $img->store('../../../public_html/writable/uploads/'); 
Reply
#2

Use base_url():
https://codeigniter.com/user_guide/helpe...l#base_url
Reply
#3

(This post was last modified: 10-07-2023, 08:53 AM by sammyskills.)

Why don't you use the move() method?

See docs.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB