CodeIgniter Forums

Full Version: @mkdir
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]zen333[/eluser]
Hi guys,

I was trying to mkdir some folder for me to store my upload files but unfortunately, I am not able to do so with the following codes. May I know if I need to configuration anything if I want to make use of @mkdir?????? I wanted to create a folder inside my CI. COuld someone please help me? Thanks!

Code:
public function import()
    {
        $user = $this->session->userdata("user");
        if($user!=null && $user->users_roles == "2")
        {
            $this->load->library("Upload");

            @mkdir( "raw/");
            @mkdir( "process/");

            $config['upload_path'] = "./raw/";
            $config['allowed_types'] = 'xls';
            $config['max_size']    = '1000';
            $config['remove_spaces']  = true;
            $config['overwrite']  = true;

            $this->upload->initialize($config);
            $this->upload->set_max(1);

            if(!$this->upload->do_upload("raw"))
            {
                $data["error"] = $this->upload->display_errors();
            }
            else
            {
                $rawFileData = $this->upload->data();

                $config['upload_path'] = "./process/";
                $config['allowed_types'] = 'xls';
                $config['max_size']    = '1000';
                $config['remove_spaces']  = true;
                $config['overwrite']  = true;

                $this->upload->initialize($config);
                $this->upload->set_max(1);

El Forum

[eluser]rogierb[/eluser]
Is mkdir enabled in your php?
If so, does the user CI is running under have rights to create dirs?

El Forum

[eluser]Dam1an[/eluser]
DO you have write access to the web root? Or wherever index.php is?
One problem I can see with this is, it will create the dirs the first time round, and then error each time as they exist (although you hide the error with the @, but thats cheating Tongue)

El Forum

[eluser]zen333[/eluser]
Hi Guys,

Thanks for the fast reply. How do I enable my write access in CI? Thanks.


Regards,
Zen

El Forum

[eluser]rogierb[/eluser]
eh, you dont, that is handled by your OS.
If you are on linux, the user that is running apache or another webserver must have write access, furthermore mkdir has to be enable in you php.ini(or at leat not disabled)
On winblows, you should be set to go

El Forum

[eluser]Yorick Peterse[/eluser]
Chmod all files to 775, in some cases you'll need to chmod them to 777. In many cases the following will also work, but again you'll need proper write permissions before you can use it.

Code:
// Do something first
....

// Chmod the parent directory
chmod("path/to/parent",0777);

// Create the directory
if(mkdir("path/to/parent/directory"))
{
   return true;
}
else
{
   return false;
}


// Process the results
....

El Forum

[eluser]n0xie[/eluser]
Before you tell users to just 'chmod 755 or 777' you might explain a bit what the implications are for this action...

El Forum

[eluser]Evil Wizard[/eluser]
[quote author="n0xie" date="1245255872"]Before you tell users to just 'chmod 755 or 777' you might explain a bit what the implications are for this action...[/quote]
Also you may want to look at the php function umask()

El Forum

[eluser]zen333[/eluser]
Hi Guys,

Many thanks for all your feedbacks. I will try them one by one.

Hi Yorick,

I have some errors running the codes that you gave me!? could you help me solve them. THanks.
A PHP Error was encountered
Severity: Warning

Message: chmod() [function.chmod]: No error

Filename: controllers/test.php

Line Number: 14

A PHP Error was encountered
Severity: Warning

Message: mkdir() [function.mkdir]: No such file or directory

Filename: controllers/test.php

Line Number: 17

THank you. Also I been trying to learn the example in CI on the "file uploading class"

[code]<?php

class Upload extends Controller {

function Upload()
{
parent::Controller();
$this->load->helper(array('form', 'url'));
}

function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}

function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());

$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());

$this->load->view('upload_success', $data);
}
}
}
?>[code]

I think it due to configuration problem that I keep on receiving a error "The upload path does not appear to be valid" ??? I try to change the code such as "$config['upload_path'] = './uploads/';" to "$config['upload_path'] = 'C:\Documents and Settings\zen\Desktop\test\uploads';" but still can't solve the problem.
Every single line of codes are the same as in CI example.....Could someone please enlighten me? Thank you so much!

Regards,
Zen

El Forum

[eluser]Evil Wizard[/eluser]
Is there a directory in the folder where index.php is called "uploads"? are the permissions set that whatever user the webserver is running as can write to the folder? but it looks as though you are on a windows system.
Pages: 1 2