Welcome Guest, Not a member yet? Register   Sign In
How to change Uploded File name?
#1

[eluser]gomji9star[/eluser]
I am using do upload function for uploading a file now i want to upload xyz.txt file with new updated name like i want to add time stamp before the filename so i am easly upload that name in database but in uploads folder do not contain the same name which is store in database.i am also at least not able to change name.pls guide me now what to do?
#2

[eluser]Thorpe Obazee[/eluser]
use the rename() function after you've uploaded it.
#3

[eluser]gomji9star[/eluser]
But some times one user upload so many files once then which file we have to rename so at that time we are confused which file we have to first rename.
#4

[eluser]Thorpe Obazee[/eluser]
I suggest you loop through the uploading process and rename then save the name in the database.
#5

[eluser]xwero[/eluser]
from 1.7.1 you can rename the file using $config['file_name']
#6

[eluser]Zeeshan Rasool[/eluser]
if you are using multiple file broswers then you can access them with their name but you have to write separate code below provided to upload each file.i-e for uploading all files.
Code:
$config['max_size']        = '800000';
$config['upload_path']     = './path..';
$config['max_width']       = '1000';
$config['max_height']      = '1000';
$config['allowed_types']   = 'gif|jpg|jpeg|png|bmp';
Here below we are getting file name that are being uploaded and after that we will get extension type . like this...
Code:
$filename            = basename($_FILES['image']['name']);
$Filename            = explode('.',$filename);
$extension           = $Filename[1];

$this->upload->initialize($config);
$this->load->library('upload', $config);
Now , give your own file name with extension that we have get. i-e
Code:
$this->upload->do_upload($image,'YOUR NAME HERE',$extension)

But you need little modification in Upload library function. Pass two param in do_upload func like this
Code:
function do_upload($field,$Name='',$Extension='')
///  ...
....
....

Change this
Code:
$this->file_name = $_FILES[$field]['name'];

TO
Code:
$this->file_name = (($Name=='') ? $_FILES[$field]['name'] : $Name );

So that if we provide our own name then it can be renamed. Otherwise not..

So Hows that?
Keep going

Cheers
#7

[eluser]xwero[/eluser]
zEsHaN the upload library already has the option to change the filename so if you want to make changes to the class for previous versions of the framework make them based on the latest framework code. The method that has been changed is _prep_filename.
#8

[eluser]Vicente Russo[/eluser]
Before de $this->upload->do_upload() function, you can change the file name this way:

Code:
$_FILES[$file]['name'] = $newname;
#9

[eluser]Zeeshan Rasool[/eluser]
Thanks xwero and Vicente Russo its very nice for me.
#10

[eluser]cmark[/eluser]
[quote author="xwero" date="1240930274"]from 1.7.1 you can rename the file using $config['file_name'][/quote]

I'm testing it, but doesn't found for me. I'm using the 1.7.1

Is the option available?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB