• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codeigniter upload question

Hi everyone,

I'm pretty new to codeigniter. I usually work in wordpress. But I have just made an upload site using a codeigniter guide online for an upload file site.

I have made it possible for when a customer registers a new folder is dynamically made using the mkdir function. My issue is that I now want the user to be able to upload their files to their generated folder (if that makes sense) I was wondering if someone would be able to talk me though how to get this to work? I've tried searching online and not found anything close to what i'm trying to do.

I've tried adding a
to the upload destination but this doesn't seem to do anything other than put the $username into the url LOL

If someone could help me that would be wonderful, i've been amazed at the power of this program and want to use it again for another project I have coming up and it would be great to be able to sort this out Smile

I hope someone can help



Try following the example from the user guide and when you get stuck, post what you have and we'll help you.

The code i've tried to use to make it work is as follows:

write_file("./files/.$username".$name, $file);

The above didn't work so I tried this:

write_file("./files/" .$username, .$name , $file);

I using it in the following code:

function upload()
            $file     = read_file($_FILES['file']['tmp_name']);
            $name     = basename($_FILES['file']['name']);
            write_file("./files/" .$name, $file);


        else $this->load->view('upload');
    function delete($id)
        //This deletes the file from the database, before returning the name of the file.
        $name = $this->files->delete($id);        
        unlink("./files/" .$name);

Is there any way to make the upload to a mkdir folder work with this code?

yes you can make it work to a mkdir folder. I would start by trying to echo the realpath using php's native realpath function to figure out the path that is actually trying to be used. http://php.net/manual/en/function.realpath.php

how about making the files come up as the username instead with a number on the end. is there a way to do this instead?

Just create the file with the username from the session data and then append a timestamp on it if you want to do it that way.

would that be at this point in the code?

$name     = basename($_FILES['file']['name']);

so I would just change it to:

$name     = basename($_FILES['$username']['name']);

or something like that?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.