Welcome Guest, Not a member yet? Register   Sign In
File permission problem
#1

[eluser]tomitzel[/eluser]
Hello,
I'm having some problems when uploading files with CodeIgniter. After upload, I set the file permission with the php function chmod to 755, but I still cannot acces the file from outside. I get a 404 for every file I've uploaded.
I've checked from my FTP account, the files appear with the permission 755.

I'm out of ideas, can someone please help me with this?

Thank you.
#2

[eluser]webroasters[/eluser]
If you're using a Linux solution, you can try to Chown the files, from a console. For example, on my server, after uploading files, I run the following command into the console.

Code:
sudo chown -R www-data:www-data /var/www/some_folder/

You can change /var/www/some_folder/ into any folder that exists on the server, inside the /var/www/ folder, or you can just own the entire folder.

Www-data is the user and group of PHP.

-R means Recursive.

Putting "Sudo" in there will mean, you'll have to put your password in next. Sudo is the root user. The master/administrator, whatever you want to call it.

If this doesn't help, you'll need to be more specific on what the problem is.
#3

[eluser]tomitzel[/eluser]
I am hosted on a Linux machine, but I don't have access to the console.
I've tried the function chown from PHP, but I get back:
Code:
Message: chown() [function.chown]: Operation not permitted
I guess you need to be superuser in order to change the owner of a file.
#4

[eluser]xeroblast[/eluser]
if you can access it via ftp then change the permission to 777...

you cant use 755 if you dont have access to the console...
#5

[eluser]tomitzel[/eluser]
I have FTP access and I've tried to set it to 777, but I receive:
Code:
Response:    550 SITE CHMOD command failed.
The file is written with the user www-data of the FTP I think and thats why I can't change permissions or its owner. I need somehow to setup codeigniter to upload the file with my FTP user and not www-data.
Plus, I need this solution because its a website with user accounts and users should be able to upload the files and then view them, so I can go on FTP for each file and change its permission.

Any other suggestions?
Thanks.
#6

[eluser]xeroblast[/eluser]
try not to change the file permission coz when you upload it, coz it is always the apache user will be the owner if run/uploaded in the browser...

so to access the then you also have to access it via the browser...
#7

[eluser]tomitzel[/eluser]
If I upload it without putting permission, then it has the permission 644 which doesn't help me.
Here is the code that does the upload:
Code:
function add_logo(){        
        $aux = str_replace("@","_",$this->session->userdata('email'));
        $aux = str_replace(".","_",$aux);
        $config['upload_path'] = './uploads/' . $aux . '/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '1000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $this->template->set('title','Add logo');
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            
            $this->template->load('template','upload/upload_logo_form', $error);
        }    
        else
        {
            $data = $this->upload->data();
            $fileid = $this->file_model->AddFile(array('name' => $data['file_name'], 'type' => 'logo', 'owner' => $this->session->userdata('userid')));
            if($fileid){
                $this->user_model->UpdateUser(array('logo' => $fileid, 'userId' => $this->session->userdata('userid')));
                
                $this->template->load('template','upload/upload_logo_succes', $data);
            }else{
                $error = array('error' => $this->upload->display_errors());            
                $this->template->load('template','upload/upload_logo_form', $error);
            }
        }
    }




Theme © iAndrew 2016 - Forum software by © MyBB