Welcome Guest, Not a member yet? Register   Sign In
Upload Class. Need numbering to start at 00
#1

[eluser]Craig Ward[/eluser]
I am using the uplaod class for images and currently the class works the names as follows:

If you upload 5 images with the name of pic, for example, it will do the following.

pic.jpg
pic1.jpg
pic2.jpg
pic3.jpg
pic4.jpg

I really need this numbering done in the following way

pic00.jpg
pic01.jpg
pic02.jpg
pic03.jpg
pic04.jpg


How would I get this to work?
#2

[eluser]Krzemo[/eluser]
Create MY_Upload.php library and alter set_filename function to behave as desired...
#3

[eluser]Craig Ward[/eluser]
Thats the part I would need help with. Are there any guides for doing it?
#4

[eluser]Hernando[/eluser]
In user guide:

http://ellislab.com/codeigniter/user-gui...aries.html

View the section: Extending Native Libraries

Cheers
#5

[eluser]Krzemo[/eluser]
In case you are looking for more precise answer... Smile

Code:
function set_filename($path, $filename)
{
    if ($this->encrypt_name == TRUE)
    {        
        mt_srand();
        $filename = md5(uniqid(mt_rand())).$this->file_ext;    
    }

    if ( ! file_exists($path.$filename))
    {
        return $filename;
    }

    $filename = str_replace($this->file_ext, '', $filename);
    
    $new_filename = '';
    for ($i = 0; $i < 100; $i++)
    {            
        if ( ! file_exists($path.$filename. (($i < 10) ? "0$i" : $i) .$this->file_ext))
        {
            $new_filename = $filename. (($i < 10) ? "0$i" : $i) .$this->file_ext;
            break;
        }
    }

    if ($new_filename == '')
    {
        $this->set_error('upload_bad_filename');
        return FALSE;
    }
    else
    {
        return $new_filename;
    }
}

Regs
K
#6

[eluser]Craig Ward[/eluser]
Your a top man Smile Will plug this in straight away Smile

Thank you very much

Kind Regards

Craig




Theme © iAndrew 2016 - Forum software by © MyBB