Welcome Guest, Not a member yet? Register   Sign In
Uploading of files
#1

[eluser]jbads[/eluser]
Im trying to create a function for a user to upload an avatar, and change it when they feel like it.

This is within

Code:
function avatar_upload(){
        //we use this variable to set the directory
    $user_id                    = $this->session->userdata('logged_in');

    //create thumbnail path
    $upload_path                = './imguploads/'.$user_id.'/';
        
    //check if file exists and if not create one
    if(!is_dir($upload_path)){        

        mkdir($upload_path, 0777);
                
    }
}

As you can see, I would like to create the necessary folder for the user based on user ID. Obviously there is more code than this which handles upload etc, but this is throwing out this error

Quote:A PHP Error was encountered

Severity: Warning

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

Filename: controllers/profile.php

Line Number: 421

Does anyone have any clues how to solve this or able to point me to a resource which could help?

Cheers

PS. I have echoed the
Code:
$user_id
and
Code:
$upload_path
and they both seem fine. If I add
Code:
base_url()
to the upload_path it no longer throws the error, but it still wont create the directory.

I'm working on XAMPP on Windows.
#2

[eluser]John_Betong[/eluser]
 
 
I made a quick search using Google and found a solution.
 
Code:
function avatar_upload(){

    //we use this variable to set the directory
    $user_id = $this->session->userdata('logged_in');

    //create thumbnail path
    $upload_path = "c:\\this_directory_will_be_created";

    echo '<h3>' .$upload_path .'</h3>';
        
    //check if directory exists and if not create one
    if(is_dir($upload_path)){
      echo 'ALREADY EXISTS';
    }else{  
      if (mkdir($upload_path, 0777))
        echo 'WORKS ON MY COMPUTER';
      else
        echo 'BACK TO THE DRAWING BOARD';
    }
    die;
  }//end func_get_arg
&nbsp;
&nbsp;
#3

[eluser]jbads[/eluser]
Awesome mate, thanks heaps, at first this Googled code doesn't appear to do much more than mine,

However, would I be right in thinking that the successful creation of the folder was based on putting the mkdir() function into a conditional statement?? As this would be a handy thing to have learned?

I didn't put in C:// part.
#4

[eluser]John_Betong[/eluser]
[quote author="jbads" date="1208255620"]Awesome mate, thanks heaps, at first this Googled code doesn't appear to do much more than mine,

However, would I be right in thinking that the successful creation of the folder was based on putting the mkdir() function into a conditional statement?? As this would be a handy thing to have learned?

I didn't put in C:// part.[/quote]
&nbsp;

Take a look at the online PHP Manual. &nbsp; I like it because it usually has quite a few cut & paste examples.

The mkdir(...) function returns a TRUE/FALSE value. If the return value is not tested then can trip you out later. My old C++ teacher reckons this applies to every function's return value!

edit: I think your problem was not using the leading double slash "//" - play about with it and see.

edit:
I also think mkdir(...) will be different when online Sad
&nbsp;
&nbsp;
Have fun...
&nbsp;
&nbsp;
&nbsp;
#5

[eluser]jbads[/eluser]
I spent ages looking at the manual. With no luck. The only thing I changed which made the code work was to put it into a conditional statement.

Anyway, now Im working on putting that little test into a function of its own which I can use for folders containing different file types.

Thanks, Jake
#6

[eluser]Justin Patel[/eluser]
hi,

if you can not create directory like that way you have mention .............

Try to get the absolute path not the relative ........

Use getcwd() - > this will return the absolute path ........

then you can populate the path for your need ....

Best of luck ,
Justin




Theme © iAndrew 2016 - Forum software by © MyBB