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

#1
[eluser]chrismitchell[/eluser]
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
Code:
$username
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

Ta

Chris

#2
[eluser]toymachiner62[/eluser]
Try following the example from the user guide and when you get stuck, post what you have and we'll help you.

#3
[eluser]chrismitchell[/eluser]
The code i've tried to use to make it work is as follows:

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

The above didn't work so I tried this:

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

I using it in the following code:

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

            $this->files->add($name);
            redirect('profile');        
        }

        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);
        redirect('profile');
    }

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

#4
[eluser]toymachiner62[/eluser]
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

#5
[eluser]chrismitchell[/eluser]
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?

#6
[eluser]toymachiner62[/eluser]
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.

#7
[eluser]chrismitchell[/eluser]
would that be at this point in the code?

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

so I would just change it to:

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

or something like that?

#8
[eluser]chrismitchell[/eluser]
bump


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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